



******************************
******************************
** Statistics for sectio A6 **
******************************
******************************

---------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/linnamarten/Dropbox (Personal)/Politiker_geografi/Bygglov/permit_appeal.l
> og
  log type:  text
 opened on:   2 Oct 2023, 16:49:57

. gl dat "/Users/linnamarten/Dropbox (Personal)/Politiker_geografi/Bygglov" 

. 
. 
. **********************************
. ** Permits at county level 2017 **
. **********************************
. use "$dat/permits_county_2017.dta", clear 

. cap drop county

. g county=""
(21 missing values generated)

. loc j=0

. foreach x in Stockholm x Uppsala Södermanland Östergötland Jönköping Kronoberg Kalmar Gotla
> nd Blekinge x Skåne Halland ///
> VästraGötaland x x Värmland Örebro Västmanland Dalarna Gävleborg Västernorrland Jämtland Vä
> sterbotten Norrbotten  {
  2. loc ++j
  3. di `j' "`x'"
  4. if inlist(`j',2,11,15,16) sum county_num
  5. else replace county="`x'" if county_num==`j'
  6. }
1Stockholm
variable county was str1 now str9
(1 real change made)
2x

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  county_num |         21    13.38095    7.612333          1         25
3Uppsala
(1 real change made)
4Södermanland
variable county was str9 now str13
(1 real change made)
5Östergötland
variable county was str13 now str14
(1 real change made)
6Jönköping
(1 real change made)
7Kronoberg
(1 real change made)
8Kalmar
(1 real change made)
9Gotland
(1 real change made)
10Blekinge
(1 real change made)
11x

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  county_num |         21    13.38095    7.612333          1         25
12Skåne
(1 real change made)
13Halland
(1 real change made)
14VästraGötaland
variable county was str14 now str16
(1 real change made)
15x

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  county_num |         21    13.38095    7.612333          1         25
16x

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  county_num |         21    13.38095    7.612333          1         25
17Värmland
(1 real change made)
18Örebro
(1 real change made)
19Västmanland
(1 real change made)
20Dalarna
(1 real change made)
21Gävleborg
(1 real change made)
22Västernorrland
(1 real change made)
23Jämtland
(1 real change made)
24Västerbotten
(1 real change made)
25Norrbotten
(1 real change made)

. 
. save "$dat/permits_county_2017.dta", replace
file /Users/linnamarten/Dropbox (Personal)/Politiker_geografi/Bygglov/permits_county_2017.dta
>  saved

. *****************
. *** Appeals *****
. *****************
. 
. use  "$dat/appeal.dta", clear

. 
. replace K="Ställningstagande" if K=="Ställningstagande/Besluttyp"
(1 real change made)

. 
. foreach var of varlist * {
  2.    rename `var' `=`var'[1]' 
  3. }

. drop in 1 
(1 observation deleted)

. destring, replace 
Länstyrelse: contains nonnumeric characters; no replace
Ärendetyp: contains nonnumeric characters; no replace
Ärendemening: contains nonnumeric characters; no replace
Ärenderubrik: contains nonnumeric characters; no replace
Åtgärd: contains nonnumeric characters; no replace
Kod: contains nonnumeric characters; no replace
InkostDatum: contains nonnumeric characters; no replace
Beslutdatum: contains nonnumeric characters; no replace
Avslutdatum: contains nonnumeric characters; no replace
Expedieringsdatum: contains nonnumeric characters; no replace
Ställningstagande: contains nonnumeric characters; no replace
bygglov: all characters numeric; replaced as byte
bostad: all characters numeric; replaced as byte
flerbostadshus: all characters numeric; replaced as byte
enbostadshus: all characters numeric; replaced as byte
radhus: all characters numeric; replaced as byte
fritidshus: all characters numeric; replaced as byte

. 
. 
. 
. ren Ärendetyp Arendetyp

. ren Ärendemening Arendemening

. ren Ärenderubrik Arenderubrik

. ren Åtgärd Atgard

. 
. rename _all, lower

. 
. ren länstyrelse county

. 
. cap drop bostad bygglov flerbostadshus enbostadshus radhus fritidshus

. 
. replace county=trim(county)
(0 real changes made)

. 
. g year=regexs(0) if regexm(inkostdatum, "^[0-9][0-9][0-9][0-9]")

. destring year, replace
year: all characters numeric; replaced as int

. 
. g nybyggnad=regexs(0) if regexm(inkostdatum, "^[0-9][0-9][0-9][0-9]")

. 
. 
. *ärendemening missing for Gävleborg, Halland, Västmanland, Östergötland in 2017
. replace arendemening=arenderubrik if mi(arendemening)
(3,682 real changes made)

. 
. foreach x in tillbyggnad strandskydd enbostadshus småhus flerbostadshus radhus fritidshus  
> ///
> parhus modulhus modulbost bostadsmodul boendepaviljong lägenhet studentbostäder {
  2. g `x'=regexs(0) if regexm(arendemening, "`x'")
  3. }
(13,863 missing values generated)
(15,324 missing values generated)
(12,200 missing values generated)
(15,510 missing values generated)
(14,754 missing values generated)
(15,427 missing values generated)
(14,569 missing values generated)
(15,448 missing values generated)
(15,519 missing values generated)
(15,515 missing values generated)
(15,512 missing values generated)
(15,511 missing values generated)
(15,327 missing values generated)
(15,507 missing values generated)

. 
. g tvåbostadshus=regexs(0) if regexm(arendemening, "t*T*våbostadshus")
(15,405 missing values generated)

. tab tvåbostadshus

 tvåbostadshus |      Freq.     Percent        Cum.
---------------+-----------------------------------
 Tvåbostadshus |          1        0.85        0.85
 tvåbostadshus |        117       99.15      100.00
---------------+-----------------------------------
         Total |        118      100.00

. g flerfamiljshus=regexs(0) if regexm(arendemening, "flerfamiljs*e*hus")
(15,512 missing values generated)

. tab flerfamiljshus

flerfamiljshus |      Freq.     Percent        Cum.
---------------+-----------------------------------
flerfamiljehus |          2       18.18       18.18
flerfamiljshus |          9       81.82      100.00
---------------+-----------------------------------
         Total |         11      100.00

. g enbostadshus2=regexs(0) if regexm(arendemening, "e*E*n-*bostads*hus")
(12,148 missing values generated)

. tab enbostadshus2

enbostadshus2 |      Freq.     Percent        Cum.
--------------+-----------------------------------
 Enbostadshus |         23        0.68        0.68
en-bostadshus |          1        0.03        0.71
  enbostadhus |         28        0.83        1.54
 enbostadshus |      3,322       98.43       99.97
  nbostadshus |          1        0.03      100.00
--------------+-----------------------------------
        Total |      3,375      100.00

. g flerbostadshus2=regexs(0) if regexm(arendemening, "f*F*ler-*bostadshus")
(14,741 missing values generated)

. tab flerbostadshus2

flerbostadshus |
             2 |      Freq.     Percent        Cum.
---------------+-----------------------------------
Flerbostadshus |         13        1.66        1.66
flerbostadshus |        769       98.34      100.00
---------------+-----------------------------------
         Total |        782      100.00

. g modulhus2=regexs(0) if regexm(arendemening, "modulbost")
(15,515 missing values generated)

. tab modulhus2

  modulhus2 |      Freq.     Percent        Cum.
------------+-----------------------------------
  modulbost |          8      100.00      100.00
------------+-----------------------------------
      Total |          8      100.00

. 
. foreach x in enbostadshus2 radhus parhus tvåbostadshus småhus {
  2. replace enbostadshus=`x' if mi(enbostadshus)
  3. }
variable enbostadshus was str12 now str13
(52 real changes made)
(82 real changes made)
(59 real changes made)
variable enbostadshus was str13 now str14
(116 real changes made)
(9 real changes made)

. 
. foreach x in flerbostadshus2 flerfamiljshus modulhus modulhus2 bostadsmodul boendepaviljong
>  lägenhet studentbostäder {
  2. replace flerbostadshus=`x' if mi(flerbostadshus)
  3. }
(13 real changes made)
(11 real changes made)
(3 real changes made)
(8 real changes made)
(11 real changes made)
variable flerbostadshus was str14 now str15
(10 real changes made)
(152 real changes made)
variable flerbostadshus was str15 now str16
(13 real changes made)

. 
. 
. foreach x in nybyggnad tillbyggnad strandskydd enbostadshus flerbostadshus  fritidshus {
  2. ren `x' `x'_ 
  3. g `x'=(!mi(`x'_))
  4. drop `x'_
  5. }

. 
. 
. ** check counties to see which ones have enough info  ***
. tab county  year if arendetyp=="Överklagande bostäder" // 13, almost all start 2017

                 |                          year
          county |      2015       2016       2017       2018       2019 |     Total
-----------------+-------------------------------------------------------+----------
       Gävleborg |         0          0         17         13         13 |        60 
         Halland |         0          2         52          0          0 |        54 
        Jämtland |         1          2          8          0          0 |        11 
       Jönköping |         0          0         11          0          0 |        11 
          Kalmar |         0          0         30          0          0 |        30 
           Skåne |         0          0        130        157        129 |       648 
       Stockholm |         0          0        357          0          0 |       357 
         Uppsala |         0          4         34          0          0 |        38 
        Värmland |         0          0         14          0          0 |        14 
    Västerbotten |         0          0         12          0          0 |        12 
  Västernorrland |         0          0          7         12         13 |        64 
     Västmanland |         0          0         18          0          0 |        18 
    Östergötland |         0          0         10          0          0 |        10 
-----------------+-------------------------------------------------------+----------
           Total |         1          8        700        182        155 |     1,327 


                 |         year
          county |      2020       2021 |     Total
-----------------+----------------------+----------
       Gävleborg |         7         10 |        60 
         Halland |         0          0 |        54 
        Jämtland |         0          0 |        11 
       Jönköping |         0          0 |        11 
          Kalmar |         0          0 |        30 
           Skåne |       103        129 |       648 
       Stockholm |         0          0 |       357 
         Uppsala |         0          0 |        38 
        Värmland |         0          0 |        14 
    Västerbotten |         0          0 |        12 
  Västernorrland |        17         15 |        64 
     Västmanland |         0          0 |        18 
    Östergötland |         0          0 |        10 
-----------------+----------------------+----------
           Total |       127        154 |     1,327 


. bys county : egen temp=max(arendetyp=="Överklagande bostäder") if year==2017
(13741 missing values generated)

. tab county  if temp==0 // Dalarna, Gotland, Kronoberg, Norrbotten, Södermanland, Västra Göt
> aland

          county |      Freq.     Percent        Cum.
-----------------+-----------------------------------
         Dalarna |         79       15.28       15.28
         Gotland |         44        8.51       23.79
       Kronoberg |          3        0.58       24.37
      Norrbotten |         55       10.64       35.01
    Södermanland |          5        0.97       35.98
  VästraGötaland |        331       64.02      100.00
-----------------+-----------------------------------
           Total |        517      100.00

. *Kronoberg, Gotland missing ärendetyp but have ärendemening 2017 (can not distinguish type 
> of building)
. * the rest mix appeals for houses with other type of buildings
. 
. 
. *check remaining 13
. foreach x in Gävleborg Halland Jämtland Jönköping Kalmar Skåne Stockholm Uppsala Värmland V
> ästerbotten Västernorrland Västmanland Östergötland {
  2. display "`x'"   
  3. tab arendetyp if year==2017 & county =="`x'"
  4. }
Gävleborg

                              arendetyp |      Freq.     Percent        Cum.
----------------------------------------+-----------------------------------
                           Överklagande |         19       15.20       15.20
                       Överklagande Lst |         37       29.60       44.80
                  Överklagande bostäder |         17       13.60       58.40
                       Överklagande lov |         52       41.60      100.00
----------------------------------------+-----------------------------------
                                  Total |        125      100.00
Halland

                              arendetyp |      Freq.     Percent        Cum.
----------------------------------------+-----------------------------------
                           Överklagande |          5        3.60        3.60
                       Överklagande Lst |         30       21.58       25.18
                  Överklagande bostäder |         52       37.41       62.59
                       Överklagande lov |         51       36.69       99.28
              Överklagande sanktionsavg |          1        0.72      100.00
----------------------------------------+-----------------------------------
                                  Total |        139      100.00
Jämtland

                              arendetyp |      Freq.     Percent        Cum.
----------------------------------------+-----------------------------------
                       Överklagande Lst |          1       11.11       11.11
                  Överklagande bostäder |          8       88.89      100.00
----------------------------------------+-----------------------------------
                                  Total |          9      100.00
Jönköping

                              arendetyp |      Freq.     Percent        Cum.
----------------------------------------+-----------------------------------
                       Överklagande Lst |          9       24.32       24.32
                  Överklagande bostäder |         11       29.73       54.05
                       Överklagande lov |         17       45.95      100.00
----------------------------------------+-----------------------------------
                                  Total |         37      100.00
Kalmar

                              arendetyp |      Freq.     Percent        Cum.
----------------------------------------+-----------------------------------
                  Överklagande bostäder |         30      100.00      100.00
----------------------------------------+-----------------------------------
                                  Total |         30      100.00
Skåne

                              arendetyp |      Freq.     Percent        Cum.
----------------------------------------+-----------------------------------
                  Överklagande bostäder |        130      100.00      100.00
----------------------------------------+-----------------------------------
                                  Total |        130      100.00
Stockholm

                              arendetyp |      Freq.     Percent        Cum.
----------------------------------------+-----------------------------------
                  Överklagande bostäder |        357      100.00      100.00
----------------------------------------+-----------------------------------
                                  Total |        357      100.00
Uppsala

                              arendetyp |      Freq.     Percent        Cum.
----------------------------------------+-----------------------------------
                  Överklagande bostäder |         34      100.00      100.00
----------------------------------------+-----------------------------------
                                  Total |         34      100.00
Värmland

                              arendetyp |      Freq.     Percent        Cum.
----------------------------------------+-----------------------------------
                  Överklagande bostäder |         14       22.95       22.95
                       Överklagande lov |         47       77.05      100.00
----------------------------------------+-----------------------------------
                                  Total |         61      100.00
Västerbotten

                              arendetyp |      Freq.     Percent        Cum.
----------------------------------------+-----------------------------------
                           Överklagande |          8        6.72        6.72
                       Överklagande Lst |         27       22.69       29.41
                  Överklagande bostäder |         12       10.08       39.50
                       Överklagande lov |         64       53.78       93.28
              Överklagande sanktionsavg |          8        6.72      100.00
----------------------------------------+-----------------------------------
                                  Total |        119      100.00
Västernorrland

                              arendetyp |      Freq.     Percent        Cum.
----------------------------------------+-----------------------------------
                  Överklagande bostäder |          7       33.33       33.33
                       Överklagande lov |         14       66.67      100.00
----------------------------------------+-----------------------------------
                                  Total |         21      100.00
Västmanland

                              arendetyp |      Freq.     Percent        Cum.
----------------------------------------+-----------------------------------
                           Överklagande |          8        9.52        9.52
                       Överklagande Lst |         18       21.43       30.95
                     Överklagande annan |          1        1.19       32.14
                  Överklagande bostäder |         18       21.43       53.57
                       Överklagande lov |         36       42.86       96.43
              Överklagande sanktionsavg |          3        3.57      100.00
----------------------------------------+-----------------------------------
                                  Total |         84      100.00
Östergötland

                              arendetyp |      Freq.     Percent        Cum.
----------------------------------------+-----------------------------------
                           Överklagande |          9        7.56        7.56
                       Överklagande Lst |         41       34.45       42.02
                  Överklagande bostäder |         10        8.40       50.42
                       Överklagande lov |         59       49.58      100.00
----------------------------------------+-----------------------------------
                                  Total |        119      100.00

. 
. * check share where we can classify type of building ***
. 
. g classify=(flerbostadshus==1 |enbostadshus==1)

. 
. foreach x in Gävleborg Halland Jämtland Jönköping Kalmar Skåne Stockholm Uppsala Värmland V
> ästerbotten Västernorrland Västmanland Östergötland {
  2. display "`x'"   
  3. sum classify  if year==2017 & arendetyp=="Överklagande bostäder" & county =="`x'"
  4. }
Gävleborg

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |         17           0           0          0          0
Halland

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |         52    .9807692     .138675          0          1
Jämtland

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |          8        .875    .3535534          0          1
Jönköping

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |         11           1           0          1          1
Kalmar

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |         30          .1    .3051286          0          1
Skåne

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |        130          .7    .4600303          0          1
Stockholm

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |        357    .8235294    .3817551          0          1
Uppsala

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |         34    .5588235    .5039947          0          1
Värmland

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |         14          .5    .5188745          0          1
Västerbotten

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |         12    .9166667    .2886751          0          1
Västernorrland

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |          7    .4285714    .5345225          0          1
Västmanland

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |         18    .7777778    .4277926          0          1
Östergötland

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |         10          .6    .5163978          0          1

. 
. *also check for sample that lack  arendetyp=="Överklagande bostäder"
. foreach x in Dalarna Gotland Kronoberg Norrbotten Södermanland VästraGötaland {
  2. display "`x'"   
  3. sum classify if year==2017  & county =="`x'" //(25-40%)
  4. }
Dalarna

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |         79    .2405063    .4301219          0          1
Gotland

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |         44    .0227273    .1507557          0          1
Kronoberg

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |          3           0           0          0          0
Norrbotten

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |         55    .2727273    .4494666          0          1
Södermanland

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |          5           0           0          0          0
VästraGötaland

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |        331    .4320242    .4961077          0          1

. 
. *over 50 % classified and arendetyp=="Överklagande bostäder" gives 10 counties
. gl samplist Halland Jämtland Jönköping Skåne Stockholm Uppsala Värmland Västerbotten Västma
> nland Östergötland 

. 
. *extra check 
. g samp=.
(15,523 missing values generated)

. foreach x in $samplist  {
  2. replace samp=1 if county =="`x'"
  3. sum classify  if year==2017 & arendetyp=="Överklagande bostäder" & county =="`x'"
  4. }
(835 real changes made)

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |         52    .9807692     .138675          0          1
(106 real changes made)

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |          8        .875    .3535534          0          1
(262 real changes made)

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |         11           1           0          1          1
(648 real changes made)

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |        130          .7    .4600303          0          1
(357 real changes made)

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |        357    .8235294    .3817551          0          1
(396 real changes made)

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |         34    .5588235    .5039947          0          1
(427 real changes made)

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |         14          .5    .5188745          0          1
(1,010 real changes made)

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |         12    .9166667    .2886751          0          1
(598 real changes made)

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |         18    .7777778    .4277926          0          1
(1,545 real changes made)

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    classify |         10          .6    .5163978          0          1

. 
. 
. *look if there are additional search words to add
. *list arendemening if year==2017 & samp==1 & classify==0 & arendetyp=="Överklagande bostäde
> r"
. 
. *check the ones with few matches 0-40 %
. * Västernorrland, Kalmar,  Gävleborg
. *list arendemening if year==2017 & samp!=1 & classify==0 & arendetyp=="Överklagande bostäde
> r"
. 
. 
. tab flerbostadshus if samp==1 & year==2017 & arendetyp=="Överklagande bostäder" // 155

flerbostads |
        hus |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |        491       76.01       76.01
          1 |        155       23.99      100.00
------------+-----------------------------------
      Total |        646      100.00

. tab enbostadshus if samp==1 & year==2017 & arendetyp=="Överklagande bostäder" // 361

enbostadshu |
          s |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |        285       44.12       44.12
          1 |        361       55.88      100.00
------------+-----------------------------------
      Total |        646      100.00

. 
. 
. *number of building permits  per kategory and county in 2017 according to our bilding permi
> ts data
. 
. bys county year: egen appeal_onefam=sum(enbostadshus)

. bys county year: egen appeal_multifam=sum(flerbostadshus)

. keep if year==2017 & arendetyp=="Överklagande bostäder"
(14,823 observations deleted)

. 
. merge m:1 county using "$dat/permits_county_2017.dta"

    Result                           # of obs.
    -----------------------------------------
    not matched                             8
        from master                         0  (_merge==1)
        from using                          8  (_merge==2)

    matched                               700  (_merge==3)
    -----------------------------------------

. drop if _merge==2 // Blekinge, Örebro
(8 observations deleted)

. drop _merge

. 
. 
. *check for sample where at least 50 % classify
. bys county : egen share=mean(classify)

. tab county share 

                 |                         share
          county |         0         .1   .4285714         .5   .5588235 |     Total
-----------------+-------------------------------------------------------+----------
       Gävleborg |        17          0          0          0          0 |        17 
         Halland |         0          0          0          0          0 |        52 
        Jämtland |         0          0          0          0          0 |         8 
       Jönköping |         0          0          0          0          0 |        11 
          Kalmar |         0         30          0          0          0 |        30 
           Skåne |         0          0          0          0          0 |       130 
       Stockholm |         0          0          0          0          0 |       357 
         Uppsala |         0          0          0          0         34 |        34 
        Värmland |         0          0          0         14          0 |        14 
    Västerbotten |         0          0          0          0          0 |        12 
  Västernorrland |         0          0          7          0          0 |         7 
     Västmanland |         0          0          0          0          0 |        18 
    Östergötland |         0          0          0          0          0 |        10 
-----------------+-------------------------------------------------------+----------
           Total |        17         30          7         14         34 |       700 


                 |                         share
          county |        .6         .7   .7777778   .8235294       .875 |     Total
-----------------+-------------------------------------------------------+----------
       Gävleborg |         0          0          0          0          0 |        17 
         Halland |         0          0          0          0          0 |        52 
        Jämtland |         0          0          0          0          8 |         8 
       Jönköping |         0          0          0          0          0 |        11 
          Kalmar |         0          0          0          0          0 |        30 
           Skåne |         0        130          0          0          0 |       130 
       Stockholm |         0          0          0        357          0 |       357 
         Uppsala |         0          0          0          0          0 |        34 
        Värmland |         0          0          0          0          0 |        14 
    Västerbotten |         0          0          0          0          0 |        12 
  Västernorrland |         0          0          0          0          0 |         7 
     Västmanland |         0          0         18          0          0 |        18 
    Östergötland |        10          0          0          0          0 |        10 
-----------------+-------------------------------------------------------+----------
           Total |        10        130         18        357          8 |       700 


                 |              share
          county |  .9166667   .9807692          1 |     Total
-----------------+---------------------------------+----------
       Gävleborg |         0          0          0 |        17 
         Halland |         0         52          0 |        52 
        Jämtland |         0          0          0 |         8 
       Jönköping |         0          0         11 |        11 
          Kalmar |         0          0          0 |        30 
           Skåne |         0          0          0 |       130 
       Stockholm |         0          0          0 |       357 
         Uppsala |         0          0          0 |        34 
        Värmland |         0          0          0 |        14 
    Västerbotten |        12          0          0 |        12 
  Västernorrland |         0          0          0 |         7 
     Västmanland |         0          0          0 |        18 
    Östergötland |         0          0          0 |        10 
-----------------+---------------------------------+----------
           Total |        12         52         11 |       700 


. 
. egen tag=tag(county)

. 
. 
. *calculate all appeals/permits per county
. g share_multifam=appeal_multifam/multifam

. g share_onefam=appeal_onefam/onefam

. 
. sum share_multifam if tag==1 & share>=0.50 // 27 %

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
share_mult~m |         10     .268271     .158509   .0434783   .4642857

. sum share_onefam if tag==1 & share>=0.50 // 7 %

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
share_onefam |         10    .0714109    .0433644       .032   .1427609

. sum share_multifam if tag==1 & share>=0.70 // 32 %

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
share_mult~m |          7    .3158596    .1584991   .0434783   .4642857

. sum share_onefam if tag==1 & share>=0.70 // 9 %

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
share_onefam |          7    .0871016    .0431186   .0394737   .1427609

. 
. *calculate all appeals/all permits
. cap drop temp

. loc x 70 // 50

. g temp=1 if share>=0.`x'  & !mi(share)
(112 missing values generated)

. 
. tab county if temp==1

          county |      Freq.     Percent        Cum.
-----------------+-----------------------------------
         Halland |         52        8.84        8.84
        Jämtland |          8        1.36       10.20
       Jönköping |         11        1.87       12.07
           Skåne |        130       22.11       34.18
       Stockholm |        357       60.71       94.90
    Västerbotten |         12        2.04       96.94
     Västmanland |         18        3.06      100.00
-----------------+-----------------------------------
           Total |        588      100.00

. egen multifam_`x'=sum(multifam) if tag==1 & temp==1
(693 missing values generated)

. egen onefam_`x'=sum(onefam) if tag==1 & temp==1
(693 missing values generated)

. egen appeal_onefam_`x'=sum(enbostadshus) if temp==1
(112 missing values generated)

. egen appeal_multifam_`x'=sum(flerbostadshus) if temp==1
(112 missing values generated)

. 
. g share_multifam_`x'=appeal_multifam_`x'/multifam_`x' 
(693 missing values generated)

. g share_onefam_`x'=appeal_onefam_`x'/onefam_`x' 
(693 missing values generated)

. 
. sum share_multifam_* share_onefam_*

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
share_mul~70 |          7    .2933071           0   .2933071   .2933071
share_one~70 |          7     .082492           0    .082492    .082492

. sum appeal_multifam_`x' appeal_onefam_`x' if temp==1

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
appeal_mu~70 |        588         149           0        149        149
appeal_on~70 |        588         335           0        335        335

. 
. drop appeal_onefam_* appeal_multifam_*  multifam_* onefam_* share_*

. 
. *0.26 and 0.07 for 50%-limit 10 counties // 155 multi 361 sing
. *0.29 and 0.08 for 70%-limit 7 counties, 149 multi 335 sing
. 
. 
. log close 
      name:  <unnamed>
       log:  /Users/linnamarten/Dropbox (Personal)/Politiker_geografi/Bygglov/permit_appeal.l
> og
  log type:  text
 closed on:   2 Oct 2023, 16:49:59
---------------------------------------------------------------------------------------------


******************
******************
** Table A2  *****
******************
******************

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz\masterlog.smcl
  log type:  smcl
 opened on:   2 Oct 2023, 15:06:59

. 
. ******************************************************************************
. 
. * Build
. do "$code1\Individ_bas"

. clear

. set more off

. sysdir set PLUS c:\ado\plus\b\

. set scheme lean2

. 
. cd "D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz"
D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz

. 
. global output "D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz\Analysis\Output"

. global input "D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz\Analysis\Data"

. 
. global source "D:\Data\GeoSweden\GeoSweden 2.0\Fastighet"

. global source2 "D:\Data\GeoSweden\GeoSweden 2.0\Basdata"

. global source3 "D:\Data\GeoSweden\GeoSweden 2.0\Louise_Lisa"

. 
. ******************************************************************************
. 
. * Individuals with link to properties 2017
. 
. use "$source2\IndData1990_2017.dta", clear

. keep IBFLopNr FoddAr

. 
. merge 1:m IBFLopNr using "$source\BefFast2017", keepusing(IBFFastLopNr) keep(mat mas) nogen

    Result                           # of obs.
    -----------------------------------------
    not matched                     3,152,364
        from master                 3,152,364  
        from using                          0  

    matched                        10,119,934  
    -----------------------------------------

. rename IBFFastLopNr fast2017

. duplicates drop IBFLopNr, force

Duplicates in terms of IBFLopNr

(0 observations are duplicates)

. 
. rename IBFLopNr ibflopnr

. rename FoddAr foddar

. keep ibflopnr foddar fast*

. order ibflopnr foddar fast*

. 
. compress
  (0 bytes saved)

. save "$input\indfast", replace
file D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz\Analysis\Data\indfast.dta saved

. 
. 
. 
end of do-file

. do "$code1\Indink"

. clear

. set more off

. sysdir set PLUS c:\ado\plus\b\

. set scheme lean2

. 
. cd "D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz"
D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz

. 
. global output "D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz\Analysis\Output"

. global input "D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz\Analysis\Data"

. 
. global source "D:\Data\GeoSweden\GeoSweden 2.0\Fastighet"

. global source2 "D:\Data\GeoSweden\GeoSweden 2.0\Basdata"

. global source3 "D:\Data\GeoSweden\GeoSweden 2.0\Louise_Lisa"

. 
. ******************************************************************************
. 
. * Program
. 
. capture program drop genindinc

. program genindinc
  1. args yr inkforv inkdisp KapInk
  2. 
. use "$input\kpi", clear
  3. keep if year == `yr'
  4. global kpi = kpi[1]
  5. 
. use "$input\indfast", clear                                                             
  6. keep ibflopnr foddar fast`yr'
  7. 
. rename ibflopnr IBFLopNr                                        /* mat-merge Lisa */
  8. merge 1:m IBFLopNr using "$source3\Louise_Lisa`yr'", keepusing(`inkforv' `KapInk' `inkdisp') keep(mat) nogen
  9. duplicates drop IBFLopNr, force
 10. rename `inkforv' inkf
 11. rename `inkdisp' inkn
 12. rename `KapInk' KapInk
 13. replace KapInk = 0 if KapInk == .
 14. gen inkt = inkf + KapInk
 15. replace inkt = . if inkn == .                                   /* inkt and inkn simultaneously non-missing */
 16. replace inkn = . if inkt == .
 17. rename IBFLopNr ibflopnr
 18. 
. * Sample selection
. replace inkt = . if fast`yr' == .                               /* empty income without codes on property */
 19. replace inkn = . if fast`yr' == .                               
 20. gen age = `yr' - foddar                                                                 
 21. replace inkt = . if age <= 19                           /* empty income non-working age */
 22. replace inkn = . if age <= 19                           
 23. 
. 
. replace inkt = 0 if inkt < 0
 24. replace inkn = 0 if inkn < 0
 25. 
. replace inkt = inkt*10/${kpi}                                   /* income in real thousands */ 
 26. replace inkn = inkn*10/${kpi}
 27. 
. rename inkt inkt`yr'
 28. rename inkn inkn`yr'
 29. 
. keep ibflopnr inkt`yr' inkn`yr' 
 30. save temp`yr', replace
 31. 
. end

. 
. * Loop program
. genindinc 2017 ForvInk DispInk04 KapInk
(27 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                         8,325,349  
    -----------------------------------------

Duplicates in terms of IBFLopNr

(0 observations are duplicates)
  (all newnames==oldnames)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(155,123 real changes made, 155,123 to missing)
(155,123 real changes made, 155,123 to missing)
(536,959 real changes made, 536,959 to missing)
(536,959 real changes made, 536,959 to missing)
(830,806 real changes made)
(41,509 real changes made)
(6,060,313 real changes made)
variable inkn was long now double
(7,467,670 real changes made)
file temp2017.dta saved

. 
. compress
  (0 bytes saved)

. save "$input\indink", replace
file D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz\Analysis\Data\indink.dta saved

. 
end of do-file

. do "$code1\fastsd"

. clear

. set more off

. sysdir set PLUS c:\ado\plus\b\

. set scheme lean2

. 
. cd "D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz"
D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz

. 
. global output "D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz\Analysis\Output"

. global input "D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz\Analysis\Data"

. 
. global source "D:\Data\GeoSweden\GeoSweden 2.0\Fastighet"

. global source2 "D:\Data\GeoSweden\GeoSweden 2.0\Basdata"

. global source3 "D:\Data\GeoSweden\GeoSweden 2.0\Louise_Lisa"

. 
. ******************************************************************************
. 
. 
. ** Program
. capture program drop genfastsd

. program genfastsd
  1. args yr
  2. 
. * Input selected individuals in indfast
. merge 1:1 ibflopnr using "$input\indfast", keepusing(fast`yr' foddar) nogen keep(mat)
  3. rename fast`yr' fast
  4. 
. * Working age sample 
. gen age = `yr' - foddar
  5. drop if age < 20
  6. 
. drop if fast == .
  7. drop age foddar
  8. 
. egen fastpopwa = count(ibflopnr), by(fast)
  9. 
. * Income
. gen inkn = inkn`yr'
 10. 
. *Gen pc
. centile inkn, centile(25 50 75)
 11. global inknpc25 = r(c_1)
 12. global inknpc50 = r(c_2)
 13. global inknpc75 = r(c_3)
 14. 
. gen inkn1q = . 
 15. replace inkn1q = 1 if inkn <= ${inknpc25}
 16. replace inkn1q = 0 if inkn > ${inknpc25} & inkn != .
 17. gen inkn2q = .
 18. replace inkn2q = 1 if inkn <= ${inknpc50} & inkn > ${inknpc25}
 19. replace inkn2q = 0 if inkn2q != 1 & inkn != .
 20. gen inkn3q = .
 21. replace inkn3q = 1 if inkn <= ${inknpc75} & inkn > ${inknpc50}
 22. replace inkn3q = 0 if inkn3q != 1 & inkn != .
 23. gen inkn4q = .
 24. replace inkn4q = 1 if inkn > ${inknpc75} & inkn != .
 25. replace inkn4q = 0 if inkn4q != 1 & inkn != .
 26. 
. * Calculate Sd 
. egen fastinknm = mean(inkn), by(fast)
 27. egen fastinkn1qm = mean(inkn1q), by(fast)
 28. egen fastinkn2qm = mean(inkn2q), by(fast)
 29. egen fastinkn3qm = mean(inkn3q), by(fast)
 30. egen fastinkn4qm = mean(inkn4q), by(fast)
 31. 
. egen fastinkn1qt = total(inkn1q), by(fast)
 32. egen fastinkn2qt = total(inkn2q), by(fast)
 33. egen fastinkn3qt = total(inkn3q), by(fast)
 34. egen fastinkn4qt = total(inkn4q), by(fast)
 35. 
. egen tot1 = total(inkn1q)
 36. egen tot2 = total(inkn2q)
 37. egen tot3 = total(inkn3q)
 38. egen tot4 = total(inkn4q)
 39. 
. duplicates drop fast, force
 40. 
. gen year = `yr'
 41. keep fast* year tot*
 42. save temp`yr', replace
 43. 
. end

. 
. 
. ** Loop program
. use "$input\indink", clear

. keep(ibflopnr inkn2017)

. genfastsd 2017

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                         8,325,349  
    -----------------------------------------
(544,813 observations deleted)
(147,269 observations deleted)

                                                       -- Binom. Interp. --
    Variable |       Obs  Percentile    Centile        [95% Conf. Interval]
-------------+-------------------------------------------------------------
        inkn | 7,633,267         25    97.21978        97.15527    97.21978
             |                   50    150.3778        150.2487    150.4423
             |                   75    209.7289        209.6644     209.858
(7,633,267 missing values generated)
(1,910,826 real changes made)
(5,722,441 real changes made)
(7,633,267 missing values generated)
(1,907,809 real changes made)
(5,725,458 real changes made)
(7,633,267 missing values generated)
(1,906,435 real changes made)
(5,726,832 real changes made)
(7,633,267 missing values generated)
(1,908,197 real changes made)
(5,725,070 real changes made)

Duplicates in terms of fast

(5,658,540 observations deleted)
file temp2017.dta saved

. 
. order fast year

. sort fast year 

. save "$input\fastsd", replace
file D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz\Analysis\Data\fastsd.dta saved

. 
end of do-file

. do "$code1\fastsoc"

. clear

. set more off

. sysdir set PLUS c:\ado\plus\b\

. set scheme lean2

. 
. cd "D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz"
D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz

. 
. global output "D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz\Analysis\Output"

. global input "D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz\Analysis\Data"

. 
. global source "D:\Data\GeoSweden\GeoSweden 2.0\Fastighet"

. global source2 "D:\Data\GeoSweden\GeoSweden 2.0\Basdata"

. global source3 "D:\Data\GeoSweden\GeoSweden 2.0\Louise_Lisa"

. 
. ******************************************************************************
. 
. * Social welfare
. use "$input\indfast", clear                                                             

. keep ibflopnr foddar fast2017

. rename fast2017 fast

. 
. rename ibflopnr IBFLopNr                                        /* mat-merge Lisa */

. merge 1:m IBFLopNr using "$source3\Louise_Lisa2017", keepusing(SocBidrPersF) keep(mat) nogen

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                         8,325,349  
    -----------------------------------------

. duplicates drop IBFLopNr, force

Duplicates in terms of IBFLopNr

(0 observations are duplicates)

. gen socbid = 0

. replace socbid = 1 if SocBidrPersF > 0
(334,858 real changes made)

. rename IBFLopNr ibflopnr

. 
. * Sample selection
. gen age = 2017 - foddar                                                                 

. drop if age <= 19                               /* drop non-working age */
(544,813 observations deleted)

. drop age foddar

. 
. * Gen mean by fast
. drop if fast == .
(147,269 observations deleted)

. egen fastsocm = mean(socbid), by(fast)

. 
. duplicates drop fast, force

Duplicates in terms of fast

(5,658,540 observations deleted)

. 
. gen year = 2017

. keep fast* year

. 
. compress
  variable year was float now int
  (3,949,454 bytes saved)

. save "$input\fastsoc", replace
file D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz\Analysis\Data\fastsoc.dta saved

. 
end of do-file

. do "$code1\fast2017"

. clear

. set more off

. sysdir set PLUS c:\ado\plus\b\

. set scheme lean2

. 
. cd "D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz"
D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz

. 
. global output "D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz\Analysis\Output"

. global input "D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz\Analysis\Data"

. 
. global source "D:\Data\GeoSweden\GeoSweden 2.0\Fastighet"

. global source2 "D:\Data\GeoSweden\GeoSweden 2.0\Basdata"

. global source3 "D:\Data\GeoSweden\GeoSweden 2.0\Louise_Lisa"

. 
. ******************************************************************************
. 
. * Properties 2017
. use "$source\Fast2017", clear

. keep IBFFastLopNr Typkod JurFormGrp

. rename Typkod multi     

. rename JurFormGrp jur   

. rename IBFFastLopNr ibffastlopnr

. order ibffastlopnr multi jur

. 
. ******************************************************************************
. 
. *Cathegorize the values
. gen own = 0

. replace own = 1 if multi > 500 & multi != .
(1,158 real changes made)

. replace multi = 0 if multi < 300 & multi != 0
(2,573,730 real changes made)

. replace multi`i' = 1 if multi`i' >= 300 & multi`i' != .
(96,051 real changes made)

. 
. gen private = 0

. replace private = 1 if jur == 4 & own != 1 & multi == 1 | jur == 6 & own != 1 & multi == 1
(47,322 real changes made)

. replace own = 1 if jur == 7 & multi == 1
(26,917 real changes made)

. replace own = 0 if jur == 8
(35 real changes made)

. gen public = 0

. replace public = 1 if jur == 1 & multi == 1 | jur == 2 & multi == 1 | jur == 8 & multi == 1
(15,041 real changes made)

. 
. gen year = 2017

. rename ibffastlopnr fast

. drop jur

. 
. compress
  variable multi was int now byte
  variable own was float now byte
  variable private was float now byte
  variable public was float now byte
  variable year was float now int
  (32,471,628 bytes saved)

. save "$input\fast2017", replace
file D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz\Analysis\Data\fast2017.dta saved

. 
end of do-file

. 
. * Analysis
. do "$code2\Graph_summarystat"

. clear

. set more off

. sysdir set PLUS c:\ado\plus\b\

. set scheme lean2

. 
. cd "D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz"
D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz

. 
. global output "D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz\Analysis\Output"

. global input "D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz\Analysis\Data"

. global input2 "D:\Userfiles\Projects\PoorHousing"

. 
. global source "D:\Data\GeoSweden\GeoSweden 2.0\Fastighet"

. global source2 "D:\Data\GeoSweden\GeoSweden 2.0\Basdata"

. global source3 "D:\Data\GeoSweden\GeoSweden 2.0\Louise_Lisa"

. 
. ******************************************************************************
. 
. use "$input\fast2017", clear

. 
. * Merge with fastink data
. merge 1:1 fast year using "$input\fastsd", keep(mat) nogen
(note: variable year was int, now float to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                         1,974,727  
    -----------------------------------------

. merge 1:1 fast year using "$input\fastsoc", keepusing(fastsocm) nogen keep(mat)

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                         1,974,727  
    -----------------------------------------

. rename fast id

. merge 1:1 id using "$input\FastRes", keepusing(residents2017) nogen keep(mat)

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                         1,974,727  
    -----------------------------------------

. rename id fast

. rename residents2017 residents

. 
. sort fast year

. order fast year

. 
. ******************************************************************************
. 
. ** Gen sample
. gen sample = .
(1,974,727 missing values generated)

. replace sample = 1 if multi == 0
(1,860,792 real changes made)

. replace sample = 2 if public == 1
(14,418 real changes made)

. replace sample = 3 if private == 1
(43,800 real changes made)

. replace sample = 4 if own == 1
(25,481 real changes made)

. replace sample = 5 if sample == . /*others*/
(30,236 real changes made)

. replace multi = . if sample == 5
(5,131 real changes made, 5,131 to missing)

. 
. gen sample2 = 1 if multi == 0
(113,935 missing values generated)

. replace sample2 = 2 if multi == 1
(83,699 real changes made)

. replace sample2 = 3 if sample2 == .
(30,236 real changes made)

. 
. gen sample3 = 1 if sample == 2 | sample == 3
(1,916,509 missing values generated)

. replace sample3 = 2 if sample3 == .
(1,916,509 real changes made)

. 
. *****************************************************************************
. 
. *Gen share rich and poor
. * POOR
. bysort sample: egen poortype = total(fastinkn1qt)

. bysort sample2: egen poortype2 = total(fastinkn1qt)

. bysort sample3: egen poortype3 = total(fastinkn1qt)

. gen sharepoor = poortype/tot1

. gen sharepoor2 = poortype2/tot1

. gen sharepoor3 = poortype3/tot1

. 
. * RICH
. bysort sample: egen richtype = total(fastinkn4qt)

. bysort sample2: egen richtype2 = total(fastinkn4qt)

. bysort sample3: egen richtype3 = total(fastinkn4qt)

. gen sharerich = richtype/tot4

. gen sharerich2 = richtype2/tot4

. gen sharerich3 = richtype3/tot4

. 
. ******************************************************************************
. 
. mat A = J(7,7,.)

. 
. * Detached houses
. egen residents_h = total(residents) if sample == 1
(113,935 missing values generated)

. sum residents_h, d

                         residents_h
-------------------------------------------------------------
      Percentiles      Smallest
 1%      5234898        5234898
 5%      5234898        5234898
10%      5234898        5234898       Obs           1,860,792
25%      5234898        5234898       Sum of Wgt.   1,860,792

50%      5234898                      Mean            5234898
                        Largest       Std. Dev.             0
75%      5234898        5234898
90%      5234898        5234898       Variance              0
95%      5234898        5234898       Skewness              .
99%      5234898        5234898       Kurtosis              .

. mat A[1, 1] = round(r(mean),.001)

. 
. asgen fastinknm1 = fastinknm if sample == 1, w(fastpopwa)

. sum fastinknm1, d

                         fastinknm1
-------------------------------------------------------------
      Percentiles      Smallest
 1%     197.7971       197.7971
 5%     197.7971       197.7971
10%     197.7971       197.7971       Obs           1,860,792
25%     197.7971       197.7971       Sum of Wgt.   1,860,792

50%     197.7971                      Mean           197.7971
                        Largest       Std. Dev.             0
75%     197.7971       197.7971
90%     197.7971       197.7971       Variance              0
95%     197.7971       197.7971       Skewness              .
99%     197.7971       197.7971       Kurtosis              .

. mat A[2, 1] = round(r(mean),.001)

. 
. asgen fastinkn1qm1 = fastinkn1qm if sample == 1, w(fastpopwa)

. sum fastinkn1qm1, d

                        fastinkn1qm1
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .1992143       .1992143
 5%     .1992143       .1992143
10%     .1992143       .1992143       Obs           1,860,792
25%     .1992143       .1992143       Sum of Wgt.   1,860,792

50%     .1992143                      Mean           .1992143
                        Largest       Std. Dev.      2.78e-17
75%     .1992143       .1992143
90%     .1992143       .1992143       Variance       7.70e-34
95%     .1992143       .1992143       Skewness             -1
99%     .1992143       .1992143       Kurtosis              1

. mat A[3, 1] = round(r(mean),.001)

. 
. asgen fastinkn4qm1 = fastinkn4qm if sample == 1, w(fastpopwa)

. sum fastinkn4qm1, d

                        fastinkn4qm1
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .3126566       .3126566
 5%     .3126566       .3126566
10%     .3126566       .3126566       Obs           1,860,792
25%     .3126566       .3126566       Sum of Wgt.   1,860,792

50%     .3126566                      Mean           .3126566
                        Largest       Std. Dev.             0
75%     .3126566       .3126566
90%     .3126566       .3126566       Variance              0
95%     .3126566       .3126566       Skewness              .
99%     .3126566       .3126566       Kurtosis              .

. mat A[4, 1] = round(r(mean),.001)

. 
. asgen fastsocm1 = fastsocm if sample == 1, w(fastpopwa)

. sum fastsocm1, d

                          fastsocm1
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .0104194       .0104194
 5%     .0104194       .0104194
10%     .0104194       .0104194       Obs           1,860,792
25%     .0104194       .0104194       Sum of Wgt.   1,860,792

50%     .0104194                      Mean           .0104194
                        Largest       Std. Dev.             0
75%     .0104194       .0104194
90%     .0104194       .0104194       Variance              0
95%     .0104194       .0104194       Skewness              .
99%     .0104194       .0104194       Kurtosis              .

. mat A[5, 1] = round(r(mean),.001)

. 
. sum sharepoor if sample == 1, d

                          sharepoor
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .3997674       .3997674
 5%     .3997674       .3997674
10%     .3997674       .3997674       Obs           1,860,792
25%     .3997674       .3997674       Sum of Wgt.   1,860,792

50%     .3997674                      Mean           .3997674
                        Largest       Std. Dev.             0
75%     .3997674       .3997674
90%     .3997674       .3997674       Variance              0
95%     .3997674       .3997674       Skewness              .
99%     .3997674       .3997674       Kurtosis              .

. mat A[6, 1] = round(r(mean),.001)

. 
. sum sharerich if sample == 1, d

                          sharerich
-------------------------------------------------------------
      Percentiles      Smallest
 1%      .628279        .628279
 5%      .628279        .628279
10%      .628279        .628279       Obs           1,860,792
25%      .628279        .628279       Sum of Wgt.   1,860,792

50%      .628279                      Mean            .628279
                        Largest       Std. Dev.             0
75%      .628279        .628279
90%      .628279        .628279       Variance              0
95%      .628279        .628279       Skewness              .
99%      .628279        .628279       Kurtosis              .

. mat A[7, 1] = round(r(mean),.001)

. 
. 
. * Multi-family houses
. egen residents_mh = total(residents) if sample >= 2 & sample < 5
(1,891,028 missing values generated)

. sum residents_mh, d

                        residents_mh
-------------------------------------------------------------
      Percentiles      Smallest
 1%      4024259        4024259
 5%      4024259        4024259
10%      4024259        4024259       Obs              83,699
25%      4024259        4024259       Sum of Wgt.      83,699

50%      4024259                      Mean            4024259
                        Largest       Std. Dev.             0
75%      4024259        4024259
90%      4024259        4024259       Variance              0
95%      4024259        4024259       Skewness              .
99%      4024259        4024259       Kurtosis              .

. mat A[1, 2] = round(r(mean),.001)

. 
. asgen fastinknm2 = fastinknm if sample >= 2 & sample < 5, w(fastpopwa)

. sum fastinknm2, d

                         fastinknm2
-------------------------------------------------------------
      Percentiles      Smallest
 1%     161.2962       161.2962
 5%     161.2962       161.2962
10%     161.2962       161.2962       Obs              83,699
25%     161.2962       161.2962       Sum of Wgt.      83,699

50%     161.2962                      Mean           161.2962
                        Largest       Std. Dev.             0
75%     161.2962       161.2962
90%     161.2962       161.2962       Variance              0
95%     161.2962       161.2962       Skewness              .
99%     161.2962       161.2962       Kurtosis              .

. mat A[2, 2] = round(r(mean),.001)

. 
. asgen fastinkn1qm2 = fastinkn1qm if sample >= 2 & sample < 5, w(fastpopwa)

. sum fastinkn1qm2, d

                        fastinkn1qm2
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .2965529       .2965529
 5%     .2965529       .2965529
10%     .2965529       .2965529       Obs              83,699
25%     .2965529       .2965529       Sum of Wgt.      83,699

50%     .2965529                      Mean           .2965529
                        Largest       Std. Dev.             0
75%     .2965529       .2965529
90%     .2965529       .2965529       Variance              0
95%     .2965529       .2965529       Skewness              .
99%     .2965529       .2965529       Kurtosis              .

. mat A[3, 2] = round(r(mean),.001)

. 
. asgen fastinkn4qm2 = fastinkn4qm if sample >= 2 & sample < 5, w(fastpopwa)

. sum fastinkn4qm2, d

                        fastinkn4qm2
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .1912315       .1912315
 5%     .1912315       .1912315
10%     .1912315       .1912315       Obs              83,699
25%     .1912315       .1912315       Sum of Wgt.      83,699

50%     .1912315                      Mean           .1912315
                        Largest       Std. Dev.             0
75%     .1912315       .1912315
90%     .1912315       .1912315       Variance              0
95%     .1912315       .1912315       Skewness              .
99%     .1912315       .1912315       Kurtosis              .

. mat A[4, 2] = round(r(mean),.001)

. 
. asgen fastsocm2 = fastsocm if sample >= 2 & sample < 5, w(fastpopwa)

. sum fastsocm2, d

                          fastsocm2
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .0619683       .0619683
 5%     .0619683       .0619683
10%     .0619683       .0619683       Obs              83,699
25%     .0619683       .0619683       Sum of Wgt.      83,699

50%     .0619683                      Mean           .0619683
                        Largest       Std. Dev.      6.94e-18
75%     .0619683       .0619683
90%     .0619683       .0619683       Variance       4.81e-35
95%     .0619683       .0619683       Skewness             -1
99%     .0619683       .0619683       Kurtosis              1

. mat A[5, 2] = round(r(mean),.001)

. 
. sum sharepoor2 if sample2 == 2, d

                         sharepoor2
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .5050868       .5050868
 5%     .5050868       .5050868
10%     .5050868       .5050868       Obs              83,699
25%     .5050868       .5050868       Sum of Wgt.      83,699

50%     .5050868                      Mean           .5050868
                        Largest       Std. Dev.             0
75%     .5050868       .5050868
90%     .5050868       .5050868       Variance              0
95%     .5050868       .5050868       Skewness              .
99%     .5050868       .5050868       Kurtosis              .

. mat A[6, 2] = round(r(mean),.001)

. 
. sum sharerich2 if sample2 == 2, d

                         sharerich2
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .3261529       .3261529
 5%     .3261529       .3261529
10%     .3261529       .3261529       Obs              83,699
25%     .3261529       .3261529       Sum of Wgt.      83,699

50%     .3261529                      Mean           .3261529
                        Largest       Std. Dev.             0
75%     .3261529       .3261529
90%     .3261529       .3261529       Variance              0
95%     .3261529       .3261529       Skewness              .
99%     .3261529       .3261529       Kurtosis              .

. mat A[7, 2] = round(r(mean),.001)

. 
. 
. * Multi-family houses, rentals
. egen residents_mhr = total(residents) if sample == 2 | sample == 3
(1,916,509 missing values generated)

. sum residents_mhr, d

                        residents_mhr
-------------------------------------------------------------
      Percentiles      Smallest
 1%      2372097        2372097
 5%      2372097        2372097
10%      2372097        2372097       Obs              58,218
25%      2372097        2372097       Sum of Wgt.      58,218

50%      2372097                      Mean            2372097
                        Largest       Std. Dev.             0
75%      2372097        2372097
90%      2372097        2372097       Variance              0
95%      2372097        2372097       Skewness              .
99%      2372097        2372097       Kurtosis              .

. mat A[1, 3] = round(r(mean),.001)

. 
. asgen fastinknm3 = fastinknm if sample == 2 | sample == 3, w(fastpopwa)

. sum fastinknm3, d

                         fastinknm3
-------------------------------------------------------------
      Percentiles      Smallest
 1%     134.1713       134.1713
 5%     134.1713       134.1713
10%     134.1713       134.1713       Obs              58,218
25%     134.1713       134.1713       Sum of Wgt.      58,218

50%     134.1713                      Mean           134.1713
                        Largest       Std. Dev.             0
75%     134.1713       134.1713
90%     134.1713       134.1713       Variance              0
95%     134.1713       134.1713       Skewness              .
99%     134.1713       134.1713       Kurtosis              .

. mat A[2, 3] = round(r(mean),.001)

. 
. asgen fastinkn1qm3 = fastinkn1qm if sample == 2 | sample == 3, w(fastpopwa)

. sum fastinkn1qm3, d

                        fastinkn1qm3
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .3520561       .3520561
 5%     .3520561       .3520561
10%     .3520561       .3520561       Obs              58,218
25%     .3520561       .3520561       Sum of Wgt.      58,218

50%     .3520561                      Mean           .3520561
                        Largest       Std. Dev.             0
75%     .3520561       .3520561
90%     .3520561       .3520561       Variance              0
95%     .3520561       .3520561       Skewness              .
99%     .3520561       .3520561       Kurtosis              .

. mat A[3, 3] = round(r(mean),.001)

. 
. asgen fastinkn4qm3 = fastinkn4qm if sample == 2 | sample == 3, w(fastpopwa)

. sum fastinkn4qm3, d

                        fastinkn4qm3
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .1155557       .1155557
 5%     .1155557       .1155557
10%     .1155557       .1155557       Obs              58,218
25%     .1155557       .1155557       Sum of Wgt.      58,218

50%     .1155557                      Mean           .1155557
                        Largest       Std. Dev.             0
75%     .1155557       .1155557
90%     .1155557       .1155557       Variance              0
95%     .1155557       .1155557       Skewness              .
99%     .1155557       .1155557       Kurtosis              .

. mat A[4, 3] = round(r(mean),.001)

. 
. asgen fastsocm3 = fastsocm if sample == 2 | sample == 3, w(fastpopwa)

. sum fastsocm3, d

                          fastsocm3
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .0990686       .0990686
 5%     .0990686       .0990686
10%     .0990686       .0990686       Obs              58,218
25%     .0990686       .0990686       Sum of Wgt.      58,218

50%     .0990686                      Mean           .0990686
                        Largest       Std. Dev.             0
75%     .0990686       .0990686
90%     .0990686       .0990686       Variance              0
95%     .0990686       .0990686       Skewness              .
99%     .0990686       .0990686       Kurtosis              .

. mat A[5, 3] = round(r(mean),.001)

. 
. sum sharepoor3 if sample3 == 1, d

                         sharepoor3
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .3409274       .3409274
 5%     .3409274       .3409274
10%     .3409274       .3409274       Obs              58,218
25%     .3409274       .3409274       Sum of Wgt.      58,218

50%     .3409274                      Mean           .3409274
                        Largest       Std. Dev.             0
75%     .3409274       .3409274
90%     .3409274       .3409274       Variance              0
95%     .3409274       .3409274       Skewness              .
99%     .3409274       .3409274       Kurtosis              .

. mat A[6, 3] = round(r(mean),.001)

. 
. sum sharerich3 if sample3 == 1, d

                         sharerich3
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .1120571       .1120571
 5%     .1120571       .1120571
10%     .1120571       .1120571       Obs              58,218
25%     .1120571       .1120571       Sum of Wgt.      58,218

50%     .1120571                      Mean           .1120571
                        Largest       Std. Dev.             0
75%     .1120571       .1120571
90%     .1120571       .1120571       Variance              0
95%     .1120571       .1120571       Skewness              .
99%     .1120571       .1120571       Kurtosis              .

. mat A[7, 3] = round(r(mean),.001)

. 
. 
. * Multi-family houses, public
. egen residents_mhrpu = total(residents) if sample == 2
(1,960,309 missing values generated)

. sum residents_mhrpu, d

                       residents_mhrpu
-------------------------------------------------------------
      Percentiles      Smallest
 1%      1254129        1254129
 5%      1254129        1254129
10%      1254129        1254129       Obs              14,418
25%      1254129        1254129       Sum of Wgt.      14,418

50%      1254129                      Mean            1254129
                        Largest       Std. Dev.             0
75%      1254129        1254129
90%      1254129        1254129       Variance              0
95%      1254129        1254129       Skewness              .
99%      1254129        1254129       Kurtosis              .

. mat A[1, 4] = round(r(mean),.001)

. 
. asgen fastinknm4 = fastinknm if sample == 2, w(fastpopwa)

. sum fastinknm4, d

                         fastinknm4
-------------------------------------------------------------
      Percentiles      Smallest
 1%        125.5          125.5
 5%        125.5          125.5
10%        125.5          125.5       Obs              14,418
25%        125.5          125.5       Sum of Wgt.      14,418

50%        125.5                      Mean              125.5
                        Largest       Std. Dev.             0
75%        125.5          125.5
90%        125.5          125.5       Variance              0
95%        125.5          125.5       Skewness              .
99%        125.5          125.5       Kurtosis              .

. mat A[2, 4] = round(r(mean),.001)

. 
. asgen fastinkn1qm4 = fastinkn1qm if sample == 2, w(fastpopwa)

. sum fastinkn1qm4, d

                        fastinkn1qm4
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .3868014       .3868014
 5%     .3868014       .3868014
10%     .3868014       .3868014       Obs              14,418
25%     .3868014       .3868014       Sum of Wgt.      14,418

50%     .3868014                      Mean           .3868014
                        Largest       Std. Dev.             0
75%     .3868014       .3868014
90%     .3868014       .3868014       Variance              0
95%     .3868014       .3868014       Skewness              .
99%     .3868014       .3868014       Kurtosis              .

. mat A[3, 4] = round(r(mean),.001)

. 
. asgen fastinkn4qm4 = fastinkn4qm if sample == 2, w(fastpopwa)

. sum fastinkn4qm4, d

                        fastinkn4qm4
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .0943257       .0943257
 5%     .0943257       .0943257
10%     .0943257       .0943257       Obs              14,418
25%     .0943257       .0943257       Sum of Wgt.      14,418

50%     .0943257                      Mean           .0943257
                        Largest       Std. Dev.             0
75%     .0943257       .0943257
90%     .0943257       .0943257       Variance              0
95%     .0943257       .0943257       Skewness              .
99%     .0943257       .0943257       Kurtosis              .

. mat A[4, 4] = round(r(mean),.001)

. 
. asgen fastsocm4 = fastsocm if sample == 2, w(fastpopwa)

. sum fastsocm4, d

                          fastsocm4
-------------------------------------------------------------
      Percentiles      Smallest
 1%      .121341        .121341
 5%      .121341        .121341
10%      .121341        .121341       Obs              14,418
25%      .121341        .121341       Sum of Wgt.      14,418

50%      .121341                      Mean            .121341
                        Largest       Std. Dev.             0
75%      .121341        .121341
90%      .121341        .121341       Variance              0
95%      .121341        .121341       Skewness              .
99%      .121341        .121341       Kurtosis              .

. mat A[5, 4] = round(r(mean),.001)

. 
. sum sharepoor if sample == 2, d

                          sharepoor
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .1932677       .1932677
 5%     .1932677       .1932677
10%     .1932677       .1932677       Obs              14,418
25%     .1932677       .1932677       Sum of Wgt.      14,418

50%     .1932677                      Mean           .1932677
                        Largest       Std. Dev.             0
75%     .1932677       .1932677
90%     .1932677       .1932677       Variance              0
95%     .1932677       .1932677       Skewness              .
99%     .1932677       .1932677       Kurtosis              .

. mat A[6, 4] = round(r(mean),.001)

. 
. sum sharerich if sample == 2, d

                          sharerich
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .0471953       .0471953
 5%     .0471953       .0471953
10%     .0471953       .0471953       Obs              14,418
25%     .0471953       .0471953       Sum of Wgt.      14,418

50%     .0471953                      Mean           .0471953
                        Largest       Std. Dev.             0
75%     .0471953       .0471953
90%     .0471953       .0471953       Variance              0
95%     .0471953       .0471953       Skewness              .
99%     .0471953       .0471953       Kurtosis              .

. mat A[7, 4] = round(r(mean),.001)

. 
. 
. * Multi-family houses, private
. egen residents_mhrpr = total(residents) if sample == 3
(1,930,927 missing values generated)

. sum residents_mhrpr, d

                       residents_mhrpr
-------------------------------------------------------------
      Percentiles      Smallest
 1%      1117968        1117968
 5%      1117968        1117968
10%      1117968        1117968       Obs              43,800
25%      1117968        1117968       Sum of Wgt.      43,800

50%      1117968                      Mean            1117968
                        Largest       Std. Dev.             0
75%      1117968        1117968
90%      1117968        1117968       Variance              0
95%      1117968        1117968       Skewness              .
99%      1117968        1117968       Kurtosis              .

. mat A[1, 5] = round(r(mean),.001)

. 
. asgen fastinknm5 = fastinknm if sample == 3, w(fastpopwa)

. sum fastinknm5, d

                         fastinknm5
-------------------------------------------------------------
      Percentiles      Smallest
 1%     143.4146       143.4146
 5%     143.4146       143.4146
10%     143.4146       143.4146       Obs              43,800
25%     143.4146       143.4146       Sum of Wgt.      43,800

50%     143.4146                      Mean           143.4146
                        Largest       Std. Dev.             0
75%     143.4146       143.4146
90%     143.4146       143.4146       Variance              0
95%     143.4146       143.4146       Skewness              .
99%     143.4146       143.4146       Kurtosis              .

. mat A[2, 5] = round(r(mean),.001)

. 
. asgen fastinkn1qm5= fastinkn1qm if sample == 3, w(fastpopwa)

. sum fastinkn1qm5, d

                        fastinkn1qm5
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .3150185       .3150185
 5%     .3150185       .3150185
10%     .3150185       .3150185       Obs              43,800
25%     .3150185       .3150185       Sum of Wgt.      43,800

50%     .3150185                      Mean           .3150185
                        Largest       Std. Dev.             0
75%     .3150185       .3150185
90%     .3150185       .3150185       Variance              0
95%     .3150185       .3150185       Skewness              .
99%     .3150185       .3150185       Kurtosis              .

. mat A[3, 5] = round(r(mean),.001)

. 
. asgen fastinkn4qm5 = fastinkn4qm if sample == 3, w(fastpopwa)

. sum fastinkn4qm5, d

                        fastinkn4qm5
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .1381862       .1381862
 5%     .1381862       .1381862
10%     .1381862       .1381862       Obs              43,800
25%     .1381862       .1381862       Sum of Wgt.      43,800

50%     .1381862                      Mean           .1381862
                        Largest       Std. Dev.             0
75%     .1381862       .1381862
90%     .1381862       .1381862       Variance              0
95%     .1381862       .1381862       Skewness              .
99%     .1381862       .1381862       Kurtosis              .

. mat A[4, 5] = round(r(mean),.001)

. 
. asgen fastsocm5 = fastsocm if sample == 3, w(fastpopwa)

. sum fastsocm5, d

                          fastsocm5
-------------------------------------------------------------
      Percentiles      Smallest
 1%      .075327        .075327
 5%      .075327        .075327
10%      .075327        .075327       Obs              43,800
25%      .075327        .075327       Sum of Wgt.      43,800

50%      .075327                      Mean            .075327
                        Largest       Std. Dev.             0
75%      .075327        .075327
90%      .075327        .075327       Variance              0
95%      .075327        .075327       Skewness              .
99%      .075327        .075327       Kurtosis              .

. mat A[5, 5] = round(r(mean),.001)

. 
. sum sharepoor if sample == 3, d

                          sharepoor
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .1476597       .1476597
 5%     .1476597       .1476597
10%     .1476597       .1476597       Obs              43,800
25%     .1476597       .1476597       Sum of Wgt.      43,800

50%     .1476597                      Mean           .1476597
                        Largest       Std. Dev.             0
75%     .1476597       .1476597
90%     .1476597       .1476597       Variance              0
95%     .1476597       .1476597       Skewness              .
99%     .1476597       .1476597       Kurtosis              .

. mat A[6, 5] = round(r(mean),.001)

. 
. sum sharerich if sample == 3, d

                          sharerich
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .0648618       .0648618
 5%     .0648618       .0648618
10%     .0648618       .0648618       Obs              43,800
25%     .0648618       .0648618       Sum of Wgt.      43,800

50%     .0648618                      Mean           .0648618
                        Largest       Std. Dev.             0
75%     .0648618       .0648618
90%     .0648618       .0648618       Variance              0
95%     .0648618       .0648618       Skewness              .
99%     .0648618       .0648618       Kurtosis              .

. mat A[7, 5] = round(r(mean),.001)

. 
. 
. * Multi-family houses, own
. egen residents_mho = total(residents) if sample == 4
(1,949,246 missing values generated)

. sum residents_mho, d

                        residents_mho
-------------------------------------------------------------
      Percentiles      Smallest
 1%      1652162        1652162
 5%      1652162        1652162
10%      1652162        1652162       Obs              25,481
25%      1652162        1652162       Sum of Wgt.      25,481

50%      1652162                      Mean            1652162
                        Largest       Std. Dev.             0
75%      1652162        1652162
90%      1652162        1652162       Variance              0
95%      1652162        1652162       Skewness              .
99%      1652162        1652162       Kurtosis              .

. mat A[1, 6] = round(r(mean),.001)

. 
. asgen fastinknm6 = fastinknm if sample == 4, w(fastpopwa)

. sum fastinknm6, d

                         fastinknm6
-------------------------------------------------------------
      Percentiles      Smallest
 1%     197.0438       197.0438
 5%     197.0438       197.0438
10%     197.0438       197.0438       Obs              25,481
25%     197.0438       197.0438       Sum of Wgt.      25,481

50%     197.0438                      Mean           197.0438
                        Largest       Std. Dev.             0
75%     197.0438       197.0438
90%     197.0438       197.0438       Variance              0
95%     197.0438       197.0438       Skewness              .
99%     197.0438       197.0438       Kurtosis              .

. mat A[2, 6] = round(r(mean),.001)

. 
. asgen fastinkn1qm6 = fastinkn1qm if sample == 4, w(fastpopwa)

. sum fastinkn1qm6, d

                        fastinkn1qm6
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .2234059       .2234059
 5%     .2234059       .2234059
10%     .2234059       .2234059       Obs              25,481
25%     .2234059       .2234059       Sum of Wgt.      25,481

50%     .2234059                      Mean           .2234059
                        Largest       Std. Dev.             0
75%     .2234059       .2234059
90%     .2234059       .2234059       Variance              0
95%     .2234059       .2234059       Skewness              .
99%     .2234059       .2234059       Kurtosis              .

. mat A[3, 6] = round(r(mean),.001)

. 
. asgen fastinkn4qm6 = fastinkn4qm if sample == 4, w(fastpopwa)

. sum fastinkn4qm6, d

                        fastinkn4qm6
-------------------------------------------------------------
      Percentiles      Smallest
 1%      .290964        .290964
 5%      .290964        .290964
10%      .290964        .290964       Obs              25,481
25%      .290964        .290964       Sum of Wgt.      25,481

50%      .290964                      Mean            .290964
                        Largest       Std. Dev.             0
75%      .290964        .290964
90%      .290964        .290964       Variance              0
95%      .290964        .290964       Skewness              .
99%      .290964        .290964       Kurtosis              .

. mat A[4, 6] = round(r(mean),.001)

. 
. asgen fastsocm6 = fastsocm if sample == 4, w(fastpopwa)

. sum fastsocm6, d

                          fastsocm6
-------------------------------------------------------------
      Percentiles      Smallest
 1%      .013074        .013074
 5%      .013074        .013074
10%      .013074        .013074       Obs              25,481
25%      .013074        .013074       Sum of Wgt.      25,481

50%      .013074                      Mean            .013074
                        Largest       Std. Dev.             0
75%      .013074        .013074
90%      .013074        .013074       Variance              0
95%      .013074        .013074       Skewness              .
99%      .013074        .013074       Kurtosis              .

. mat A[5, 6] = round(r(mean),.001)

. 
. sum sharepoor if sample == 4, d

                          sharepoor
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .1641594       .1641594
 5%     .1641594       .1641594
10%     .1641594       .1641594       Obs              25,481
25%     .1641594       .1641594       Sum of Wgt.      25,481

50%     .1641594                      Mean           .1641594
                        Largest       Std. Dev.             0
75%     .1641594       .1641594
90%     .1641594       .1641594       Variance              0
95%     .1641594       .1641594       Skewness              .
99%     .1641594       .1641594       Kurtosis              .

. mat A[6, 6] = round(r(mean),.001)

. 
. sum sharerich if sample == 4, d

                          sharerich
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .2140958       .2140958
 5%     .2140958       .2140958
10%     .2140958       .2140958       Obs              25,481
25%     .2140958       .2140958       Sum of Wgt.      25,481

50%     .2140958                      Mean           .2140958
                        Largest       Std. Dev.             0
75%     .2140958       .2140958
90%     .2140958       .2140958       Variance              0
95%     .2140958       .2140958       Skewness              .
99%     .2140958       .2140958       Kurtosis              .

. mat A[7, 6] = round(r(mean),.001)

. 
. 
. * Multi-family houses, other
. egen residents_o = total(residents) if sample == 5
(1,944,491 missing values generated)

. sum residents_o, d

                         residents_o
-------------------------------------------------------------
      Percentiles      Smallest
 1%       687436         687436
 5%       687436         687436
10%       687436         687436       Obs              30,236
25%       687436         687436       Sum of Wgt.      30,236

50%       687436                      Mean             687436
                        Largest       Std. Dev.             0
75%       687436         687436
90%       687436         687436       Variance              0
95%       687436         687436       Skewness              .
99%       687436         687436       Kurtosis              .

. mat A[1, 7] = round(r(mean),.001)

. 
. asgen fastinknm7 = fastinknm if sample == 5, w(fastpopwa)

. sum fastinknm7, d

                         fastinknm7
-------------------------------------------------------------
      Percentiles      Smallest
 1%     149.5807       149.5807
 5%     149.5807       149.5807
10%     149.5807       149.5807       Obs              30,236
25%     149.5807       149.5807       Sum of Wgt.      30,236

50%     149.5807                      Mean           149.5807
                        Largest       Std. Dev.             0
75%     149.5807       149.5807
90%     149.5807       149.5807       Variance              0
95%     149.5807       149.5807       Skewness              .
99%     149.5807       149.5807       Kurtosis              .

. mat A[2, 7] = round(r(mean),.001)

. 
. asgen fastinkn1qm7 = fastinkn1qm if sample == 5, w(fastpopwa)

. sum fastinkn1qm7, d

                        fastinkn1qm7
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .3340395       .3340395
 5%     .3340395       .3340395
10%     .3340395       .3340395       Obs              30,236
25%     .3340395       .3340395       Sum of Wgt.      30,236

50%     .3340395                      Mean           .3340395
                        Largest       Std. Dev.             0
75%     .3340395       .3340395
90%     .3340395       .3340395       Variance              0
95%     .3340395       .3340395       Skewness              .
99%     .3340395       .3340395       Kurtosis              .

. mat A[3, 7] = round(r(mean),.001)

. 
. asgen fastinkn4qm7 = fastinkn4qm if sample == 5, w(fastpopwa)

. sum fastinkn4qm7, d

                        fastinkn4qm7
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .1597614       .1597614
 5%     .1597614       .1597614
10%     .1597614       .1597614       Obs              30,236
25%     .1597614       .1597614       Sum of Wgt.      30,236

50%     .1597614                      Mean           .1597614
                        Largest       Std. Dev.             0
75%     .1597614       .1597614
90%     .1597614       .1597614       Variance              0
95%     .1597614       .1597614       Skewness              .
99%     .1597614       .1597614       Kurtosis              .

. mat A[4, 7] = round(r(mean),.001)

. 
. asgen fastsocm7 = fastsocm if sample == 5, w(fastpopwa)

. sum fastsocm7, d

                          fastsocm7
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .0656019       .0656019
 5%     .0656019       .0656019
10%     .0656019       .0656019       Obs              30,236
25%     .0656019       .0656019       Sum of Wgt.      30,236

50%     .0656019                      Mean           .0656019
                        Largest       Std. Dev.             0
75%     .0656019       .0656019
90%     .0656019       .0656019       Variance              0
95%     .0656019       .0656019       Skewness              .
99%     .0656019       .0656019       Kurtosis              .

. mat A[5, 7] = round(r(mean),.001)

. 
. sum sharepoor if sample == 5, d

                          sharepoor
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .0951458       .0951458
 5%     .0951458       .0951458
10%     .0951458       .0951458       Obs              30,236
25%     .0951458       .0951458       Sum of Wgt.      30,236

50%     .0951458                      Mean           .0951458
                        Largest       Std. Dev.             0
75%     .0951458       .0951458
90%     .0951458       .0951458       Variance              0
95%     .0951458       .0951458       Skewness              .
99%     .0951458       .0951458       Kurtosis              .

. mat A[6, 7] = round(r(mean),.001)

. 
. sum sharerich if sample == 5, d

                          sharerich
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .0455681       .0455681
 5%     .0455681       .0455681
10%     .0455681       .0455681       Obs              30,236
25%     .0455681       .0455681       Sum of Wgt.      30,236

50%     .0455681                      Mean           .0455681
                        Largest       Std. Dev.             0
75%     .0455681       .0455681
90%     .0455681       .0455681       Variance              0
95%     .0455681       .0455681       Skewness              .
99%     .0455681       .0455681       Kurtosis              .

. mat A[7, 7] = round(r(mean),.001)

. 
. 
. mat colnames A = "Detached" "Multi" "Rentals" "Public" "Private" "Own" "Other"

. mat rownames A = "Residents" "Disposable income" "Share Q1" "Share Q4" "Share soc" "Share poor" "Share rich"

. 
. sysdir set PLUS c:\ado\plus\

. esttab m(A) using "$output\Matris_Matz.tex", replace title("Income by house type in 2017") ///
> addnote("Table 1. Inflation adjusted income measured in thousands of SEK.")
(output written to D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz\Analysis\Output\Matris_Matz.tex)

. 
. 
. 
end of do-file

. 
. 
. *esttab m(A) using "D:\Userfiles\Personal\gabki722\Neighborhood Preferences\Matz\Matris_Matz.tex", replace title("Income by house type in 2017") addnote("Table 1. Inflation adjusted income measured in th
> ousands of SEK.")
. 
. 
end of do-file

. 






**************************
**************************
***   Figure  A2   *****
**************************
**************************

---------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/linnamarten/Dropbox (Personal)/Politiker_geografi/politiker_kartor/map.lo
> g
  log type:  text
 opened on:   2 Oct 2023, 16:51:36

. 
. 
. *election result
. import excel "$dat/2018_K_per_valdistrikt.xlsx", sheet("K procent") cellrange(A1:Q6326) fir
> strow clear

. 
. ren LÄNSKOD lan

. ren KOMMUNKOD kom

. ren VALDISTRIKTSKOD vald

. 
. loc j 0

. foreach x in lan kom vald {
  2. loc ++j
  3. tostring `x' ,replace
  4. g t`j'=length(`x')
  5. }
lan was byte now str2
kom was byte now str2
vald was int now str4

. replace lan="0"+lan if t1==1
(2,620 real changes made)

. replace kom="0"+kom if t2==1
(138 real changes made)

. replace vald="0"+vald if t3==3
(4,423 real changes made)

. replace vald="00"+vald if t3==2
(56 real changes made)

. replace vald="000"+vald if t3==1
(360 real changes made)

. 
. g VD=lan+kom+vald

. g t4=length(VD)

. tab t4

         t4 |      Freq.     Percent        Cum.
------------+-----------------------------------
          8 |      6,325      100.00      100.00
------------+-----------------------------------
      Total |      6,325      100.00

. drop t1 t2 t3 t4

. 
. 
. *check that it matches with the map
. merge 1:1 VD using "$map2018/swe"

    Result                           # of obs.
    -----------------------------------------
    not matched                           321
        from master                       321  (_merge==1)
        from using                          0  (_merge==2)

    matched                             6,004  (_merge==3)
    -----------------------------------------

. tab VALDISTRIKTSNAMN if _merge==1 // uppsamlingsdistrikt

                       VALDISTRIKTSNAMN |      Freq.     Percent        Cum.
----------------------------------------+-----------------------------------
                    Uppsamlingsdistrikt |        321      100.00      100.00
----------------------------------------+-----------------------------------
                                  Total |        321      100.00

. drop if _merge==1
(321 observations deleted)

. 
. keep VD lan kom vald M C L KD S V MP SD 

. 
. sort VD

. *drop if F=="Uppsamlingsdistrikt"
. g id=_n

. 
. saveold "$dat/result_2018.dta", replace version(12)
(saving in Stata 12 format, which can be read by Stata 11 or 12)
  note: variable label "LÄNSKOD" contains unicode and thus may not display well in Stata
        13.
file /Users/linnamarten/Dropbox (Personal)/Politiker_geografi/politiker_kartor/data/result_20
> 18.dta saved

. 
. 
. *create map
. use "$map2018/swe", clear

. describe

Contains data from /Users/linnamarten/Dropbox (Personal)/Politiker_geografi/politiker_kartor/
> data/alla_valdistrikt_2018/swe.dta
  obs:         6,004                          
 vars:            15                          10 Jan 2021 22:45
 size:     1,494,996                          
---------------------------------------------------------------------------------------------
              storage   display    value
variable name   type    format     label      variable label
---------------------------------------------------------------------------------------------
LAN             str2    %9s                   LAN
LAN_NAMN        str23   %23s                  LAN_NAMN
RVK             str2    %9s                   RVK
RVK_NAMN        str32   %32s                  RVK_NAMN
LND             str2    %9s                   LND
LND_NAMN        str34   %34s                  LND_NAMN
LVK             str4    %9s                   LVK
LVK_NAMN        str39   %39s                  LVK_NAMN
KOM             str4    %9s                   KOM
NAMN_KOM        str15   %15s                  NAMN_KOM
KVK             str6    %9s                   KVK
KVK_NAMN        str35   %35s                  KVK_NAMN
VD              str8    %9s                   VD
VD_NAMN         str41   %41s                  VD_NAMN
_ID             int     %12.0g                
---------------------------------------------------------------------------------------------
Sorted by: _ID

. merge 1:1 VD using "$dat/result_2018.dta"

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                             6,004  (_merge==3)
    -----------------------------------------

. drop _merge

. 
. 
. g cons_votes= M+C+KD+L
(22 missing values generated)

. g cons_votes_alt= ((M+C+KD+L)/(M+C+L+KD+S+V+MP))*100
(41 missing values generated)

. 
. gl add osize(thin) legt("Vote share Center-Right") legend(position(5)) legstyle(2) ocolor(w
> hite white white white white white white white white white)

. colorpalette HCL bluered2, n(4) reverse nograph

. 
. spmap cons_votes_alt using  "$map2018/swecoord" if kom=="02" & lan=="14" , id(_ID)  fcolor(
> `r(p)')  title("Vote shares and politicians in Partille") ///
> clm(c)  clb(20 40  50 60  80) $add ///
> point(data("$dat/politicians.dta") select(drop if Kommun!="Partille"  ) ///
> x(sweref99lon) y(sweref99lat) fcolor(edkblue maroon) by(party) legenda(on)  )
(Written by R.              )

. graph export "$fig/figA2.eps", replace
(file /Users/linnamarten/Dropbox (Personal)/Politiker_geografi/politiker_kartor/figures/figA2
> .eps written in EPS format)

. 
. log close 
      name:  <unnamed>
       log:  /Users/linnamarten/Dropbox (Personal)/Politiker_geografi/politiker_kartor/map.lo
> g
  log type:  text
 closed on:   2 Oct 2023, 16:51:45
---------------------------------------------------------------------------------------------












********************************
********************************
***   Dataset homeowners   *****
********************************
********************************

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  D:\UserFiles\Projects\Emigration\Native_flight\log\housetypes_new.smcl
  log type:  smcl
 opened on:   2 Oct 2023, 15:08:53

. 
. cd "E:\GeoSweden\GeoSweden Stata\Alla register\Fastighet"
E:\GeoSweden\GeoSweden Stata\Alla register\Fastighet

. foreach year in 1990 1995{
  2. clear all
  3. use "fast`year'.dta", clear
  4. rename IBFFastLopnr IBFFastLopNR
  5. merge 1:m IBFFastLopNR using "beffast`year'.dta"
  6. 
. keep if _merge==3
  7. drop _merge
  8. 
. gen tenure=5 
  9. replace tenure=1 if JurFormGrp==4 &(Typkod>200 & Typkod<300) 
 10. replace tenure=2 if JurFormGrp==7 
 11. replace tenure=3 if JurFormGrp==8 & Typkod>200 
 12. replace tenure=4 if JurFormGrp==4 & Typkod>300 
 13. replace tenure=4 if JurFormGrp==6 & Typkod>300 
 14. replace tenure=6 if JurFormGrp==4 & Typkod==120
 15. replace tenure=7 if JurFormGrp==5 
 16.  
. label variable tenure tenure 
 17. label define tenure 1 "owner-occupied" 2 "tenant-owner cooperative" 3 "public rental" 4 "private rental" 5 "other" 6 "agricultural" 7 "death"
 18. label values tenure tenure
 19. 
. compress
 20. save "D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_`year'.dta", replace
 21. }

    Result                           # of obs.
    -----------------------------------------
    not matched                       257,597
        from master                         2  (_merge==1)
        from using                    257,595  (_merge==2)

    matched                         8,332,947  (_merge==3)
    -----------------------------------------
(257,597 observations deleted)
(4,009,550 real changes made)
(1,061,259 real changes made)
(1,396,900 real changes made)
(382,820 real changes made)
(360,707 real changes made)
(318,111 real changes made)
(87,724 real changes made)
  variable tenure was float now byte
  (24,998,841 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_1990.dta saved

    Result                           # of obs.
    -----------------------------------------
    not matched                       165,232
        from master                         7  (_merge==1)
        from using                    165,225  (_merge==2)

    matched                         8,672,071  (_merge==3)
    -----------------------------------------
(165,232 observations deleted)
(4,058,064 real changes made)
(1,191,533 real changes made)
(1,300,956 real changes made)
(359,817 real changes made)
(613,491 real changes made)
(381,660 real changes made)
(23,928 real changes made)
  variable tenure was float now byte
  (26,016,213 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_1995.dta saved

. 
. foreach year in 1996{
  2. clear all
  3. use "fast`year'.dta", clear
  4. rename IBFFastLopnr IBFFastLopNr
  5. 
. bysort IBFFastLopNr: gen dup=cond(_N==1, 0, _n)
  6. keep if dup==0| dup==1
  7. drop dup
  8. 
. merge 1:m IBFFastLopNr using "beffast`year'.dta"
  9. 
. keep if _merge==3
 10. drop _merge
 11. 
. rename JurformGrp JurFormGrp
 12. 
. gen tenure=5 
 13. replace tenure=1 if JurFormGrp==4 &(Typkod>200 & Typkod<300) 
 14. replace tenure=2 if JurFormGrp==7 
 15. replace tenure=3 if JurFormGrp==8 & Typkod>200 
 16. replace tenure=4 if JurFormGrp==4 & Typkod>300 
 17. replace tenure=4 if JurFormGrp==6 & Typkod>300 
 18. replace tenure=6 if JurFormGrp==4 & Typkod==120
 19. replace tenure=7 if JurFormGrp==5 
 20.  
. label variable tenure tenure 
 21. label define tenure 1 "owner-occupied" 2 "tenant-owner cooperative" 3 "public rental" 4 "private rental" 5 "other" 6 "agricultural" 7 "death"
 22. label values tenure tenure
 23. 
. compress
 24. save "D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_`year'.dta", replace
 25. }
(54 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                       165,382
        from master                        54  (_merge==1)
        from using                    165,328  (_merge==2)

    matched                         8,678,953  (_merge==3)
    -----------------------------------------
(165,382 observations deleted)
(4,068,103 real changes made)
(1,197,904 real changes made)
(1,331,961 real changes made)
(358,601 real changes made)
(546,011 real changes made)
(382,367 real changes made)
(23,692 real changes made)
  variable tenure was float now byte
  (26,036,859 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_1996.dta saved

. 
. 
. foreach year in 1997 1998 1999{
  2. clear all
  3. use "fast`year'.dta", clear
  4. rename IBFFastLopnr IBFFastLopNr
  5. 
. bysort IBFFastLopNr: gen dup=cond(_N==1, 0, _n)
  6. keep if dup==0| dup==1
  7. drop dup
  8. 
. merge 1:m IBFFastLopNr using "beffast`year'.dta"
  9. 
. keep if _merge==3
 10. drop _merge
 11. 
. gen tenure=5 
 12. replace tenure=1 if JurFormGrp==4 &(Typkod>200 & Typkod<300) 
 13. replace tenure=2 if JurFormGrp==7 
 14. replace tenure=3 if JurFormGrp==8 & Typkod>200 
 15. replace tenure=4 if JurFormGrp==4 & Typkod>300 
 16. replace tenure=4 if JurFormGrp==6 & Typkod>300 
 17. replace tenure=6 if JurFormGrp==4 & Typkod==120
 18. replace tenure=7 if JurFormGrp==5 
 19.  
. label variable tenure tenure 
 20. label define tenure 1 "owner-occupied" 2 "tenant-owner cooperative" 3 "public rental" 4 "private rental" 5 "other" 6 "agricultural" 7 "death"
 21. label values tenure tenure
 22. 
. compress
 23. save "D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_`year'.dta", replace
 24. }
(52 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                       161,262
        from master                        20  (_merge==1)
        from using                    161,242  (_merge==2)

    matched                         8,686,155  (_merge==3)
    -----------------------------------------
(161,262 observations deleted)
(4,078,997 real changes made)
(1,196,364 real changes made)
(1,307,199 real changes made)
(348,850 real changes made)
(586,776 real changes made)
(452,846 real changes made)
(23,080 real changes made)
  variable tenure was float now byte
  (26,058,465 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_1997.dta saved
(37 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                       156,098
        from master                         1  (_merge==1)
        from using                    156,097  (_merge==2)

    matched                         8,698,199  (_merge==3)
    -----------------------------------------
(156,098 observations deleted)
(4,081,401 real changes made)
(1,200,089 real changes made)
(1,295,077 real changes made)
(345,735 real changes made)
(604,506 real changes made)
(448,763 real changes made)
(29,702 real changes made)
  variable tenure was float now byte
  (26,094,597 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_1998.dta saved
(31 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                       143,023
        from master                         0  (_merge==1)
        from using                    143,023  (_merge==2)

    matched                         8,718,379  (_merge==3)
    -----------------------------------------
(143,023 observations deleted)
(4,086,281 real changes made)
(1,216,086 real changes made)
(1,273,244 real changes made)
(338,788 real changes made)
(618,972 real changes made)
(443,672 real changes made)
(40,121 real changes made)
  variable tenure was float now byte
  (26,155,137 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_1999.dta saved

. 
. foreach year in 2000{
  2. clear all
  3. use "fast`year'.dta", clear
  4. rename IBFFastLopnr IBFFastLopNR
  5. 
. bysort IBFFastLopNR: gen dup=cond(_N==1, 0, _n)
  6. keep if dup==0| dup==1
  7. drop dup
  8. 
. merge 1:m IBFFastLopNR using "beffast`year'.dta"
  9. 
. keep if _merge==3
 10. drop _merge
 11. 
. gen tenure=5 
 12. replace tenure=1 if JurFormGrp==4 &(Typkod>200 & Typkod<300) 
 13. replace tenure=2 if JurFormGrp==7 
 14. replace tenure=3 if JurFormGrp==8 & Typkod>200 
 15. replace tenure=4 if JurFormGrp==4 & Typkod>300 
 16. replace tenure=4 if JurFormGrp==6 & Typkod>300 
 17. replace tenure=6 if JurFormGrp==4 & Typkod==120
 18. replace tenure=7 if JurFormGrp==5 
 19.  
. label variable tenure tenure 
 20. label define tenure 1 "owner-occupied" 2 "tenant-owner cooperative" 3 "public rental" 4 "private rental" 5 "other" 6 "agricultural" 7 "death"
 21. label values tenure tenure
 22. 
. compress
 23. save "D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_`year'.dta", replace
 24. }
(0 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                       139,110
        from master                         0  (_merge==1)
        from using                    139,110  (_merge==2)

    matched                         8,743,682  (_merge==3)
    -----------------------------------------
(139,110 observations deleted)
(4,119,791 real changes made)
(1,219,611 real changes made)
(1,251,915 real changes made)
(343,524 real changes made)
(642,442 real changes made)
(440,194 real changes made)
(19,262 real changes made)
  variable tenure was float now byte
  (26,231,046 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2000.dta saved

. 
. 
. foreach year in 2001 2003 2004 2005 2006 2007 2008 2009 2010{
  2. clear all
  3. use "fast`year'.dta", clear
  4. rename IBFFastLopnr IBFFastLopNr
  5. 
. bysort IBFFastLopNr: gen dup=cond(_N==1, 0, _n)
  6. keep if dup==0| dup==1
  7. drop dup
  8. 
. merge 1:m IBFFastLopNr using "beffast`year'.dta"
  9. 
. keep if _merge==3
 10. drop _merge
 11. 
. gen tenure=5 
 12. replace tenure=1 if JurFormGrp==4 &(Typkod>200 & Typkod<300) 
 13. replace tenure=2 if JurFormGrp==7 
 14. replace tenure=3 if JurFormGrp==8 & Typkod>200 
 15. replace tenure=4 if JurFormGrp==4 & Typkod>300 
 16. replace tenure=4 if JurFormGrp==6 & Typkod>300 
 17. replace tenure=6 if JurFormGrp==4 & Typkod==120
 18. replace tenure=7 if JurFormGrp==5 
 19.  
. label variable tenure tenure 
 20. label define tenure 1 "owner-occupied" 2 "tenant-owner cooperative" 3 "public rental" 4 "private rental" 5 "other" 6 "agricultural" 7 "death"
 21. label values tenure tenure
 22. 
. compress
 23. save "D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_`year'.dta", replace
 24. }
(42 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                       138,707
        from master                         0  (_merge==1)
        from using                    138,707  (_merge==2)

    matched                         8,770,391  (_merge==3)
    -----------------------------------------
(138,707 observations deleted)
(4,081,805 real changes made)
(1,219,243 real changes made)
(1,264,337 real changes made)
(330,678 real changes made)
(642,737 real changes made)
(431,969 real changes made)
(70,357 real changes made)
  variable tenure was float now byte
  (26,311,173 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2001.dta saved
(4 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                       128,433
        from master                         0  (_merge==1)
        from using                    128,433  (_merge==2)

    matched                         8,847,211  (_merge==3)
    -----------------------------------------
(128,433 observations deleted)
(4,187,097 real changes made)
(1,296,446 real changes made)
(1,253,018 real changes made)
(328,994 real changes made)
(597,284 real changes made)
(431,201 real changes made)
(25,170 real changes made)
  variable tenure was float now byte
  (26,541,633 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2003.dta saved
(0 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                       129,628
        from master                         0  (_merge==1)
        from using                    129,628  (_merge==2)

    matched                         8,881,730  (_merge==3)
    -----------------------------------------
(129,628 observations deleted)
(4,218,670 real changes made)
(1,313,792 real changes made)
(1,216,597 real changes made)
(323,238 real changes made)
(631,183 real changes made)
(430,360 real changes made)
(23,614 real changes made)
  variable tenure was float now byte
  (26,645,190 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2004.dta saved
(0 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                       127,229
        from master                         1  (_merge==1)
        from using                    127,228  (_merge==2)

    matched                         8,920,476  (_merge==3)
    -----------------------------------------
(127,229 observations deleted)
(4,254,855 real changes made)
(1,341,793 real changes made)
(1,244,895 real changes made)
(311,990 real changes made)
(606,908 real changes made)
(429,022 real changes made)
(22,080 real changes made)
  variable tenure was float now byte
  (26,761,428 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2005.dta saved
(0 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                       117,688
        from master                         1  (_merge==1)
        from using                    117,687  (_merge==2)

    matched                         8,995,515  (_merge==3)
    -----------------------------------------
(117,688 observations deleted)
(4,297,429 real changes made)
(1,369,951 real changes made)
(1,262,905 real changes made)
(301,824 real changes made)
(627,129 real changes made)
(422,608 real changes made)
(20,102 real changes made)
  variable tenure was float now byte
  (26,986,545 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2006.dta saved
(0 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                       122,347
        from master                         0  (_merge==1)
        from using                    122,347  (_merge==2)

    matched                         9,060,514  (_merge==3)
    -----------------------------------------
(122,347 observations deleted)
(4,335,600 real changes made)
(1,402,611 real changes made)
(1,249,537 real changes made)
(291,002 real changes made)
(643,737 real changes made)
(418,993 real changes made)
(19,322 real changes made)
  variable tenure was float now byte
  (27,181,542 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2007.dta saved
(0 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                       124,314
        from master                         3  (_merge==1)
        from using                    124,311  (_merge==2)

    matched                         9,131,980  (_merge==3)
    -----------------------------------------
(124,314 observations deleted)
(4,369,881 real changes made)
(1,450,845 real changes made)
(1,231,540 real changes made)
(282,895 real changes made)
(669,242 real changes made)
(416,033 real changes made)
(17,914 real changes made)
  variable tenure was float now byte
  (27,395,940 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2008.dta saved
(0 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                       123,117
        from master                         0  (_merge==1)
        from using                    123,117  (_merge==2)

    matched                         9,217,555  (_merge==3)
    -----------------------------------------
(123,117 observations deleted)
(4,397,749 real changes made)
(1,519,965 real changes made)
(1,224,231 real changes made)
(276,148 real changes made)
(673,911 real changes made)
(413,818 real changes made)
(16,058 real changes made)
  variable tenure was float now byte
  (27,652,665 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2009.dta saved
(0 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                       120,269
        from master                         0  (_merge==1)
        from using                    120,269  (_merge==2)

    matched                         9,295,278  (_merge==3)
    -----------------------------------------
(120,269 observations deleted)
(4,413,130 real changes made)
(1,557,533 real changes made)
(1,229,362 real changes made)
(268,764 real changes made)
(696,707 real changes made)
(410,548 real changes made)
(17,952 real changes made)
  variable tenure was float now byte
  (27,885,834 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2010.dta saved

. 
. ***Year 2002****
. 
. foreach year in 2002{
  2. clear all
  3. use "fast`year'_utan dubbletter.dta", clear
  4. rename IBFFastLopNR IBFFastLopNr
  5. 
. bysort IBFFastLopNr: gen dup=cond(_N==1, 0, _n)
  6. keep if dup==0| dup==1
  7. drop dup
  8. 
. merge 1:m IBFFastLopNr using "beffast`year'.dta"
  9. 
. keep if _merge==3
 10. drop _merge
 11. 
. gen tenure=5 
 12. replace tenure=1 if JurFormGrp==4 &(Typkod>200 & Typkod<300) 
 13. replace tenure=2 if JurFormGrp==7 
 14. replace tenure=3 if JurFormGrp==8 & Typkod>200 
 15. replace tenure=4 if JurFormGrp==4 & Typkod>300 
 16. replace tenure=4 if JurFormGrp==6 & Typkod>300 
 17. replace tenure=6 if JurFormGrp==4 & Typkod==120
 18. replace tenure=7 if JurFormGrp==5 
 19.  
. label variable tenure tenure 
 20. label define tenure 1 "owner-occupied" 2 "tenant-owner cooperative" 3 "public rental" 4 "private rental" 5 "other" 6 "agricultural" 7 "death"
 21. label values tenure tenure
 22. 
. compress
 23. save "D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_`year'.dta", replace
 24. }
(5,520 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                       279,112
        from master                    21,169  (_merge==1)
        from using                    257,943  (_merge==2)

    matched                         8,682,845  (_merge==3)
    -----------------------------------------
(279,112 observations deleted)
(4,133,935 real changes made)
(1,254,668 real changes made)
(1,217,758 real changes made)
(334,514 real changes made)
(595,994 real changes made)
(430,552 real changes made)
(25,976 real changes made)
  variable tenure was float now byte
  (26,048,535 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2002.dta saved

. 
. ***Year 2011 to 2014****
. 
. foreach year in 2011 2012 2013 2014{
  2. clear all
  3. use "IBF_FastTax`year'.dta", clear
  4. rename IBFFastLopnr IBFFastLopNr
  5. 
. bysort IBFFastLopNr: gen dup=cond(_N==1, 0, _n)
  6. keep if dup==0| dup==1
  7. drop dup
  8. 
. merge 1:m IBFFastLopNr using "IBF_Bef`year't.dta"
  9. 
. keep if _merge==3
 10. drop _merge
 11. 
. gen tenure=5 
 12. replace tenure=1 if JurFormGrp==4 &(Typkod>200 & Typkod<300) 
 13. replace tenure=2 if JurFormGrp==7 
 14. replace tenure=3 if JurFormGrp==8 & Typkod>200 
 15. replace tenure=4 if JurFormGrp==4 & Typkod>300 
 16. replace tenure=4 if JurFormGrp==6 & Typkod>300 
 17. replace tenure=6 if JurFormGrp==4 & Typkod==120
 18. replace tenure=7 if JurFormGrp==5 
 19.  
. label variable tenure tenure 
 20. label define tenure 1 "owner-occupied" 2 "tenant-owner cooperative" 3 "public rental" 4 "private rental" 5 "other" 6 "agricultural" 7 "death"
 21. label values tenure tenure
 22. 
. compress
 23. save "D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_`year'.dta", replace
 24. }
(0 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                       122,386
        from master                         0  (_merge==1)
        from using                    122,386  (_merge==2)

    matched                         9,360,412  (_merge==3)
    -----------------------------------------
(122,386 observations deleted)
(4,432,451 real changes made)
(1,585,632 real changes made)
(1,234,341 real changes made)
(257,991 real changes made)
(719,610 real changes made)
(406,614 real changes made)
(20,407 real changes made)
  variable tenure was float now byte
  (28,081,236 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2011.dta saved
(0 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                       126,298
        from master                         0  (_merge==1)
        from using                    126,298  (_merge==2)

    matched                         9,429,554  (_merge==3)
    -----------------------------------------
(126,298 observations deleted)
(4,443,024 real changes made)
(1,618,908 real changes made)
(1,244,653 real changes made)
(250,573 real changes made)
(735,593 real changes made)
(406,140 real changes made)
(22,150 real changes made)
  variable tenure was float now byte
  (28,288,662 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2012.dta saved
(0 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                       130,844
        from master                         1  (_merge==1)
        from using                    130,843  (_merge==2)

    matched                         9,513,990  (_merge==3)
    -----------------------------------------
(130,844 observations deleted)
(4,453,875 real changes made)
(1,656,845 real changes made)
(1,255,459 real changes made)
(244,335 real changes made)
(763,754 real changes made)
(401,879 real changes made)
(22,578 real changes made)
  variable tenure was float now byte
  (28,541,970 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2013.dta saved
(0 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                       134,402
        from master                         1  (_merge==1)
        from using                    134,401  (_merge==2)

    matched                         9,612,930  (_merge==3)
    -----------------------------------------
(134,402 observations deleted)
(4,473,594 real changes made)
(1,696,032 real changes made)
(1,265,436 real changes made)
(236,374 real changes made)
(800,167 real changes made)
(400,908 real changes made)
(22,450 real changes made)
  variable tenure was float now byte
  (28,838,790 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2014.dta saved

. 
. foreach year in 1990 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2013 2014 {
  2. clear all
  3. use "D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_`year'.dta", clear
  4. 
. rename *, lower
  5. 
. rename samsomrade sams
  6. 
. *Generate municipality variable 
. gen str9 sams_string=string(sams, "%08.0f") 
  7. gen municipality = substr(sams_string, 1, 4)
  8. destring municipality, replace
  9. 
.  *Generate share owners
. gen owner = 1 if tenure==1 | tenure==2
 10. replace owner = 0 if tenure== 3| tenure== 4
 11. 
.  *Generate share rental
. gen rental = 1 if tenure==3 | tenure==4
 12. replace rental = 0 if tenure==1 | tenure==2 
 13. 
. bysort municipality: egen mean_owner_mun = mean(owner)
 14. bysort sams: egen mean_owner_sams = mean(owner)
 15. 
. bysort municipality: egen mean_rental_mun = mean(rental)
 16. bysort sams: egen mean_rental_sams = mean(rental)
 17. 
. gen year = `year'
 18. order ibflopnr year sams
 19. 
. compress
 20. save "D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_`year'.dta", replace
 21. }
municipality: all characters numeric; replaced as int
(3,262,138 missing values generated)
(2,140,427 real changes made)
(6,192,520 missing values generated)
(5,070,809 real changes made)
(13,701 missing values generated)
(13,701 missing values generated)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  variable sams_string was str9 now str8
  (74,996,523 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_1990.dta saved
municipality: all characters numeric; replaced as int
(3,422,474 missing values generated)
(2,274,264 real changes made)
(6,397,807 missing values generated)
(5,249,597 real changes made)
(14,800 missing values generated)
(14,800 missing values generated)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  variable sams_string was str9 now str8
  (78,048,639 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_1995.dta saved
municipality: all characters numeric; replaced as int
(32 missing values generated)
(3,412,946 missing values generated)
(2,236,573 real changes made)
(6,442,380 missing values generated)
(5,266,007 real changes made)
(18,772 missing values generated)
(18,772 missing values generated)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  variable sams_string was str9 now str8
  (78,110,577 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_1996.dta saved
municipality: all characters numeric; replaced as int
(33 missing values generated)
(3,410,794 missing values generated)
(2,242,825 real changes made)
(6,443,330 missing values generated)
(5,275,361 real changes made)
(21,163 missing values generated)
(21,163 missing values generated)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  variable sams_string was str9 now str8
  (78,175,395 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_1997.dta saved
municipality: all characters numeric; replaced as int
(24 missing values generated)
(3,416,709 missing values generated)
(2,245,318 real changes made)
(6,452,881 missing values generated)
(5,281,490 real changes made)
(20,939 missing values generated)
(20,939 missing values generated)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  variable sams_string was str9 now str8
  (78,283,791 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_1998.dta saved
municipality: all characters numeric; replaced as int
(24 missing values generated)
(3,416,012 missing values generated)
(2,231,004 real changes made)
(6,487,375 missing values generated)
(5,302,367 real changes made)
(21,798 missing values generated)
(21,798 missing values generated)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  variable sams_string was str9 now str8
  (78,465,411 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_1999.dta saved
municipality: all characters numeric; replaced as int
(3,404,280 missing values generated)
(2,237,881 real changes made)
(6,505,801 missing values generated)
(5,339,402 real changes made)
(21,341 missing values generated)
(21,341 missing values generated)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  variable sams_string was str9 now str8
  (78,693,138 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2000.dta saved
municipality: all characters numeric; replaced as int
(12 missing values generated)
(3,469,343 missing values generated)
(2,237,752 real changes made)
(6,532,639 missing values generated)
(5,301,048 real changes made)
(22,347 missing values generated)
(22,347 missing values generated)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  variable sams_string was str9 now str8
  (78,933,519 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2001.dta saved
municipality: all characters numeric; replaced as int
(3,294,242 missing values generated)
(2,148,266 real changes made)
(6,534,579 missing values generated)
(5,388,603 real changes made)
(25,037 missing values generated)
(25,037 missing values generated)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  variable sams_string was str9 now str8
  (78,145,605 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2002.dta saved
municipality: all characters numeric; replaced as int
(13 missing values generated)
(3,363,668 missing values generated)
(2,179,296 real changes made)
(6,667,915 missing values generated)
(5,483,543 real changes made)
(36,319 missing values generated)
(36,319 missing values generated)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  variable sams_string was str9 now str8
  (79,624,899 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2003.dta saved
municipality: all characters numeric; replaced as int
(47 missing values generated)
(3,349,268 missing values generated)
(2,171,018 real changes made)
(6,710,712 missing values generated)
(5,532,462 real changes made)
(37,815 missing values generated)
(37,815 missing values generated)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  variable sams_string was str9 now str8
  (79,935,570 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2004.dta saved
municipality: all characters numeric; replaced as int
(20 missing values generated)
(3,323,828 missing values generated)
(2,163,793 real changes made)
(6,756,683 missing values generated)
(5,596,648 real changes made)
(34,623 missing values generated)
(34,623 missing values generated)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  variable sams_string was str9 now str8
  (80,284,284 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2005.dta saved
municipality: all characters numeric; replaced as int
(1 missing value generated)
(3,328,135 missing values generated)
(2,191,858 real changes made)
(6,803,657 missing values generated)
(5,667,380 real changes made)
(1 missing value generated)
(34,986 missing values generated)
(1 missing value generated)
(34,986 missing values generated)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  variable sams_string was str9 now str8
  (80,959,635 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2006.dta saved
municipality: all characters numeric; replaced as int
(1 missing value generated)
(3,322,303 missing values generated)
(2,184,276 real changes made)
(6,876,238 missing values generated)
(5,738,211 real changes made)
(1 missing value generated)
(35,861 missing values generated)
(1 missing value generated)
(35,861 missing values generated)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  variable sams_string was str9 now str8
  (81,544,626 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2007.dta saved
municipality: all characters numeric; replaced as int
(3,311,254 missing values generated)
(2,183,677 real changes made)
(6,948,303 missing values generated)
(5,820,726 real changes made)
(35,842 missing values generated)
(35,842 missing values generated)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  variable sams_string was str9 now str8
  (82,187,820 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2008.dta saved
municipality: all characters numeric; replaced as int
(3,299,841 missing values generated)
(2,174,290 real changes made)
(7,043,265 missing values generated)
(5,917,714 real changes made)
(36,833 missing values generated)
(36,833 missing values generated)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  variable sams_string was str9 now str8
  (82,957,995 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2009.dta saved
municipality: all characters numeric; replaced as int
(266 missing values generated)
(3,324,615 missing values generated)
(2,194,833 real changes made)
(7,100,445 missing values generated)
(5,970,663 real changes made)
(38,554 missing values generated)
(38,554 missing values generated)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  variable sams_string was str9 now str8
  (83,657,502 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2010.dta saved
municipality: all characters numeric; replaced as int
(3,403,270 missing values generated)
(2,263,548 real changes made)
(7,250,442 missing values generated)
(6,110,720 real changes made)
(37,077 missing values generated)
(37,077 missing values generated)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  variable sams_string was str9 now str8
  (85,625,910 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2013.dta saved
municipality: all characters numeric; replaced as int
(3,443,304 missing values generated)
(2,301,977 real changes made)
(7,310,953 missing values generated)
(6,169,626 real changes made)
(35,743 missing values generated)
(35,743 missing values generated)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  variable sams_string was str9 now str8
  (86,516,370 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2014.dta saved

. 
. foreach year in 2011 2012{
  2. clear all
  3. use "D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_`year'.dta", clear
  4. 
. rename *, lower
  5. 
. rename samsomrade sams
  6. 
. *Generate municipality variable 
. destring sams, generate (sams_string) force 
  7. gen municipality = substr(sams, 1, 4)
  8. destring municipality, replace
  9. 
. rename sams sams2
 10. rename sams_string sams
 11. rename sams2 sams_string
 12.  *Generate share owners
. gen owner = 1 if tenure==1 | tenure==2
 13. replace owner = 0 if tenure== 3| tenure== 4
 14. 
.  *Generate share rental
. gen rental = 1 if tenure==3 | tenure==4
 15. replace rental = 0 if tenure==1 | tenure==2 
 16. 
. bysort municipality: egen mean_owner_mun = mean(owner)
 17. bysort sams: egen mean_owner_sams = mean(owner)
 18. 
. bysort municipality: egen mean_rental_mun = mean(rental)
 19. bysort sams: egen mean_rental_sams = mean(rental)
 20. 
. gen year = `year'
 21. order ibflopnr year sams
 22. 
. compress
 23. save "D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_`year'.dta", replace
 24. }
sams: contains nonnumeric characters; sams_string generated as long
(2 missing values generated)
municipality: all characters numeric; replaced as int
(3,342,329 missing values generated)
(2,211,942 real changes made)
(7,148,470 missing values generated)
(6,018,083 real changes made)
(37,532 missing values generated)
(37,532 missing values generated)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  (74,883,296 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2011.dta saved
sams: contains nonnumeric characters; sams_string generated as long
(2 missing values generated)
municipality: all characters numeric; replaced as int
(3,367,622 missing values generated)
(2,230,819 real changes made)
(7,198,735 missing values generated)
(6,061,932 real changes made)
(37,461 missing values generated)
(37,461 missing values generated)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  (75,436,432 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2012.dta saved

. 
. foreach year in 2016 2017{
  2. clear all
  3. use "IBF_FastTax`year'.dta", clear
  4. 
. bysort ibffastlopnr_2015: gen dup=cond(_N==1, 0, _n)
  5. keep if dup==0| dup==1
  6. drop dup
  7. 
. merge 1:m ibffastlopnr_2015 using "IBF_Bef`year't.dta"
  8. 
. keep if _merge==3
  9. drop _merge
 10. 
. gen tenure=5 
 11. replace tenure=1 if jurformgrp==4 &(typkod>200 & typkod<300) 
 12. replace tenure=2 if jurformgrp==7 
 13. replace tenure=3 if jurformgrp==8 & typkod>200 
 14. replace tenure=4 if jurformgrp==4 & typkod>300 
 15. replace tenure=4 if jurformgrp==6 & typkod>300 
 16. replace tenure=6 if jurformgrp==4 & typkod==120
 17. replace tenure=7 if jurformgrp==5 
 18.  
. label variable tenure tenure 
 19. label define tenure 1 "owner-occupied" 2 "tenant-owner cooperative" 3 "public rental" 4 "private rental" 5 "other" 6 "agricultural" 7 "death"
 20. label values tenure tenure
 21. 
. rename ibffastlopnr_2015 ibffastlopnr
 22. 
. compress
 23. save "D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_`year'.dta", replace
 24. }
(0 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                       925,666
        from master                   725,390  (_merge==1)
        from using                    200,276  (_merge==2)

    matched                         9,794,835  (_merge==3)
    -----------------------------------------
(925,666 observations deleted)
(4,495,978 real changes made)
(1,751,505 real changes made)
(1,299,935 real changes made)
(230,068 real changes made)
(847,523 real changes made)
(399,711 real changes made)
(24,985 real changes made)
  variable tenure was float now byte
  (29,384,505 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2016.dta saved
(0 observations deleted)

    Result                           # of obs.
    -----------------------------------------
    not matched                       931,168
        from master                   729,088  (_merge==1)
        from using                    202,080  (_merge==2)

    matched                         9,658,567  (_merge==3)
    -----------------------------------------
(931,168 observations deleted)
(4,447,726 real changes made)
(1,753,798 real changes made)
(1,249,888 real changes made)
(207,628 real changes made)
(854,998 real changes made)
(393,688 real changes made)
(23,113 real changes made)
  variable tenure was float now byte
  (28,975,701 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2017.dta saved

. 
. foreach year in 2016 2017{
  2. clear all
  3. use "D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_`year'.dta", clear
  4. 
. rename *, lower
  5. 
.  *Generate share owners
. gen owner = 1 if tenure==1 | tenure==2
  6. replace owner = 0 if tenure== 3| tenure== 4
  7. 
.  *Generate share rental
. gen rental = 1 if tenure==3 | tenure==4
  8. replace rental = 0 if tenure==1 | tenure==2 
  9. 
. gen year = `year'
 10. order ibflopnr year 
 11. 
. compress
 12. save "D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_`year'.dta", replace
 13. }
  (all newnames==oldnames)
(3,547,352 missing values generated)
(2,377,526 real changes made)
(7,417,309 missing values generated)
(6,247,483 real changes made)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  (78,358,680 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2016.dta saved
  (all newnames==oldnames)
(3,457,043 missing values generated)
(2,312,514 real changes made)
(7,346,053 missing values generated)
(6,201,524 real changes made)
  variable year was float now int
  variable owner was float now byte
  variable rental was float now byte
  (77,268,536 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2017.dta saved

. 
. foreach year in 1990 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2013 2014{
  2. clear all
  3. use "D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_`year'.dta", clear
  4. 
. gen rentalinclallbuild = 0
  5. replace rentalinclallbuild = 1 if tenure==3 | tenure==4
  6. 
. gen ownerinclallbuild = 0
  7. replace ownerinclallbuild = 1 if tenure==1 | tenure==2
  8. 
. bysort municipality: egen mean_owner_muninclallbuild = mean(ownerinclallbuild)
  9. bysort sams: egen mean_owner_samsinclallbuild = mean(ownerinclallbuild)
 10. 
. bysort municipality: egen mean_rental_muninclallbuild = mean(rentalinclallbuild)
 11. bysort sams: egen mean_rental_samsinclallbuild = mean(rentalinclallbuild)
 12. 
. order ibflopnr year 
 13. 
. compress
 14. save "D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_`year'.dta", replace
 15. }
(2,140,427 real changes made)
(5,070,809 real changes made)
  variable rentalinclallbuild was float now byte
  variable ownerinclallbuild was float now byte
  (49,997,682 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_1990.dta saved
(2,274,264 real changes made)
(5,249,597 real changes made)
  variable rentalinclallbuild was float now byte
  variable ownerinclallbuild was float now byte
  (52,032,426 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_1995.dta saved
(2,236,573 real changes made)
(5,266,007 real changes made)
  variable rentalinclallbuild was float now byte
  variable ownerinclallbuild was float now byte
  (52,073,718 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_1996.dta saved
(2,242,825 real changes made)
(5,275,361 real changes made)
  variable rentalinclallbuild was float now byte
  variable ownerinclallbuild was float now byte
  (52,116,930 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_1997.dta saved
(2,245,318 real changes made)
(5,281,490 real changes made)
  variable rentalinclallbuild was float now byte
  variable ownerinclallbuild was float now byte
  (52,189,194 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_1998.dta saved
(2,231,004 real changes made)
(5,302,367 real changes made)
  variable rentalinclallbuild was float now byte
  variable ownerinclallbuild was float now byte
  (52,310,274 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_1999.dta saved
(2,237,881 real changes made)
(5,339,402 real changes made)
  variable rentalinclallbuild was float now byte
  variable ownerinclallbuild was float now byte
  (52,462,092 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2000.dta saved
(2,237,752 real changes made)
(5,301,048 real changes made)
  variable rentalinclallbuild was float now byte
  variable ownerinclallbuild was float now byte
  (52,622,346 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2001.dta saved
(2,148,266 real changes made)
(5,388,603 real changes made)
  variable rentalinclallbuild was float now byte
  variable ownerinclallbuild was float now byte
  (52,097,070 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2002.dta saved
(2,179,296 real changes made)
(5,483,543 real changes made)
  variable rentalinclallbuild was float now byte
  variable ownerinclallbuild was float now byte
  (53,083,266 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2003.dta saved
(2,171,018 real changes made)
(5,532,462 real changes made)
  variable rentalinclallbuild was float now byte
  variable ownerinclallbuild was float now byte
  (53,290,380 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2004.dta saved
(2,163,793 real changes made)
(5,596,648 real changes made)
  variable rentalinclallbuild was float now byte
  variable ownerinclallbuild was float now byte
  (53,522,856 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2005.dta saved
(2,191,858 real changes made)
(5,667,380 real changes made)
  variable rentalinclallbuild was float now byte
  variable ownerinclallbuild was float now byte
  (53,973,090 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2006.dta saved
(2,184,276 real changes made)
(5,738,211 real changes made)
  variable rentalinclallbuild was float now byte
  variable ownerinclallbuild was float now byte
  (54,363,084 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2007.dta saved
(2,183,677 real changes made)
(5,820,726 real changes made)
  variable rentalinclallbuild was float now byte
  variable ownerinclallbuild was float now byte
  (54,791,880 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2008.dta saved
(2,174,290 real changes made)
(5,917,714 real changes made)
  variable rentalinclallbuild was float now byte
  variable ownerinclallbuild was float now byte
  (55,305,330 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2009.dta saved
(2,194,833 real changes made)
(5,970,663 real changes made)
  variable rentalinclallbuild was float now byte
  variable ownerinclallbuild was float now byte
  (55,771,668 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2010.dta saved
(2,263,548 real changes made)
(6,110,720 real changes made)
  variable rentalinclallbuild was float now byte
  variable ownerinclallbuild was float now byte
  (57,083,940 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2013.dta saved
(2,301,977 real changes made)
(6,169,626 real changes made)
  variable rentalinclallbuild was float now byte
  variable ownerinclallbuild was float now byte
  (57,677,580 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2014.dta saved

. 
. foreach year in 2016 2017{
  2. clear all
  3. use "D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_`year'.dta", clear
  4. 
. gen rentalinclallbuild = 0
  5. replace rentalinclallbuild = 1 if tenure==3 | tenure==4
  6. 
. gen ownerinclallbuild = 0
  7. replace ownerinclallbuild = 1 if tenure==1 | tenure==2
  8. 
. order ibflopnr year 
  9. 
. compress
 10. save "D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_`year'.dta", replace
 11. }
(2,377,526 real changes made)
(6,247,483 real changes made)
  variable rentalinclallbuild was float now byte
  variable ownerinclallbuild was float now byte
  (58,769,010 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2016.dta saved
(2,312,514 real changes made)
(6,201,524 real changes made)
  variable rentalinclallbuild was float now byte
  variable ownerinclallbuild was float now byte
  (57,951,402 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_2017.dta saved

. 
. 
. foreach year in 1990 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2013 2014{
  2. clear all
  3. use "D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_`year'.dta", clear
  4. 
. collapse rentalinclallbuild ownerinclallbuild mean_owner_muninclallbuild mean_rental_muninclallbuild, by(municipality)
  5. 
. save "D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebymun_`year'.dta", replace
  6. }
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebymun_1990.dta saved
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebymun_1995.dta saved
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebymun_1996.dta saved
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebymun_1997.dta saved
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebymun_1998.dta saved
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebymun_1999.dta saved
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebymun_2000.dta saved
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebymun_2001.dta saved
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebymun_2002.dta saved
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebymun_2003.dta saved
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebymun_2004.dta saved
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebymun_2005.dta saved
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebymun_2006.dta saved
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebymun_2007.dta saved
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebymun_2008.dta saved
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebymun_2009.dta saved
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebymun_2010.dta saved
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebymun_2013.dta saved
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebymun_2014.dta saved

. 
. foreach year in 1990 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2013 2014{
  2. clear all
  3. use "D:\UserFiles\Projects\Emigration\Native_flight\data\housetypes_`year'.dta", clear
  4. 
. collapse rentalinclallbuild ownerinclallbuild, by(sams)
  5. 
. compress
  6. 
. save "D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebysams_`year'.dta", replace
  7. }
  (0 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebysams_1990.dta saved
  (0 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebysams_1995.dta saved
  (0 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebysams_1996.dta saved
  (0 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebysams_1997.dta saved
  (0 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebysams_1998.dta saved
  (0 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebysams_1999.dta saved
  (0 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebysams_2000.dta saved
  (0 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebysams_2001.dta saved
  (0 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebysams_2002.dta saved
  (0 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebysams_2003.dta saved
  (0 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebysams_2004.dta saved
  (0 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebysams_2005.dta saved
  (0 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebysams_2006.dta saved
  (0 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebysams_2007.dta saved
  (0 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebysams_2008.dta saved
  (0 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebysams_2009.dta saved
  (0 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebysams_2010.dta saved
  (0 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebysams_2013.dta saved
  (0 bytes saved)
file D:\UserFiles\Projects\Emigration\Native_flight\data\meanhousetypebysams_2014.dta saved

. 
end of do-file

